Is JPA locking considered atomic?
I am using Eclipse Link implementation, but maybe this is relevant also for Hibernate. At some point I called:
em.lock(entity, LockModeType.OPTIMISTIC_FORCE_INCREMENT);
Which I considered as an atomic operation.
Surprisingly - after putting a breakpoint on the @Version
field, it seems that there many calls to entity._persistence_get
and entity._persistence_set
.
Apparently - it is possible to get to the same point with a debugger, using two browsers, and switch between the Threads while it is still running those hidden functions. When this is done - it's impossible for both threads to flush/commit later.
Is there a change this would happen when not on Release Mode, or is it onl开发者_如何学Goy because of the debugger?
Regards, Daniel
There is no way (AFAIK) to prevent context switches in Java. Thus, I don't see how locking could be atomic in this sense. But I also don't see why it would matter anyway, since an attached entity is not supposed to be used concurrently by several threads.
精彩评论