I have a Grails/Groovy application and I want to use the OptimisticLockType DIRTY. I made this annotations:
@DynamicUpdate(true)
@OptimisticLocking(type = OptimisticLockType.DIRTY)
@SelectBeforeUpdate
class OutboundMessage implements Message {
I log all the statements in the database (postgresq), but the query still looks like: update outbound_message set version=$1, userdefined1=$2 where id=$3 and version=$4
It seems that the OptimisticLocking does not change anything.
I also tried without SelectBeforeUpdate
The code is just:
OutboundMessage msg = OutboundMessage.read(517)
msg.setUserdefined1(System.currentTimeMillis() + "")
msg.save(flush:true)
I followed this: https://vladmihalcea.com/how-to-prevent-optimisticlockexception-using-hibernate-versionless-optimistic-locking/
Edit: I found a way to get rid of the version column on the update.
static mapping = {
tablePerConcreteClass true
dynamicUpdate true
version false
}
So it seems Grails ignores the annotations. I did not find a way to set the OptimisticLocking Type