I have Groovy/Grails application, Hibernate 5.7.3.1, JDK 8.
My application has many background processes, sometimes I get a HibernateOptimisticLockingFailureException
In this case, I reload the Gorm Object from the database, apply the changes again and then save it again. This works.
The recovery code looks like:
} catch (HibernateOptimisticLockingFailureException holfe) {
def changedData = [:]
ticketstore.listDirtyPropertyNames().each {
changedData[it] = ticketstore[it]
}
Ticketstore.withNewTransaction {
ticketstore.refresh()
changedData.each {
if (ticketstore[it.key] != it.value) {
ticketstore[it.key] = it.value
}
}
ticketstore.save(flush:true)
}
This works. But afterwards, on a different Object, when I use the .save() Method, the same exception is thrown again, with the same Error Message that happened before is thrown again. It seems like Hibernate has "remembered" the error before and does not want to save afterwards. How can I solve this issue?