concurrency - @Version in hibernate, when running in cluster env does not work...(Optimistic Lock) -
i have entity uses @version on 1 of fields, want achieve if 2 transactions modify entity in same time, 1 fail(and optimistic lock exception) , other succeed.
when run test on single jvm works fine, when run in cluster env, 2 transactions succeed , no optimistic lock thrown.
public class deploymentlock { @column(name = "deployment_counter") private long deploymentcounter; @version @column(name = "entity_version") private long version; ... }
am missing something? need use "@generated(generationtime.always)" under @version?
im using spring , hibrnate in app way... idea?
if have 2 instances of deploymentlock
inside of 2 different hibernate sessions (usually in 2 different jvms or on 2 different hosts) each same version
value, 2nd of updates call should throw hibernateoptimisticlockingfailureexception
.
basically hibernate doing like:
update deploymentlock set deploymentcounter = ..., version = 2 version = 1
then if update did not change row exception thrown.
are sure 2 different jvms (or 2 sessions) have same instance same version
value? there refresh()
somewhere don't expect or maybe race conditions causing 2nd instance query return updated deploymentlock
?
maybe add logging or println
debugging print version value right before update. if show versions same can edit post show how making update call?
Comments
Post a Comment