I ran into the same problem when writing a migration that used grailsChange
. In my case, it would run hundreds of transactions successfully, and then fail on the outermost transaction that is most likely associated with the grailsChange
itself.
Switching from withTransaction
to withNewSession
resolved the issue.
You should not need to manually flush the new session. If you continue to run into issues, I'd suggest adding validate:true
and flush:true
to the save call and making use of the error(String message)
method in GrailsChange.groovy
.
grailsChange {
change {
def list1 = [record1,record2]
list1.each {
DomainClass.withTransaction {
def domain = new DomainClass(it)
if (!domain.save(validate: true, flush: true)) {
error("There was a problem saving the domain.")
}
}
}
}
}