Lock acquisition on entity persisted without clearing returns lock mode PESSIMISTIC_FORCE_INCREMENT
Description
When persisting an entity and then acquiring a lock on that entity always results in em.getLockMode(entity) = PESSIMISTIC_FORCE_INCREMENT if in the same transaction and the entity manager is not cleared.
If query is executed in another transaction, then it returns the requested lock mode.
If the entity manager is cleared between persist and query, then it returns the requested lock mode.
This happens also for entities without the @Version attribute: it always returns PESSIMISTIC_FORCE_INCREMENT, even if this lock mode is not supported by such entities.
Executed queries, however, seem to be correct (“for update” query when pessimistic lock is requested, no “for update” query when optimistic / no lock is requested).
I have prepared a sample repository with exhaustive test cases: .
This issue starts from 6.6.0.Final.
By the way, in 6.4.x and 6.5.x, I also observed that:
requesting lock mode NONE always results into OPTIMISTIC / OPTIMISTIC_FORCE_INCREMENT;
requesting lock mode OPTIMISTIC without clearing entity manager results into OPTIMISTIC_FORCE_INCREMENT.
When persisting an entity and then acquiring a lock on that entity always results in
em.getLockMode(entity) = PESSIMISTIC_FORCE_INCREMENT
if in the same transaction and the entity manager is not cleared.If query is executed in another transaction, then it returns the requested lock mode.
If the entity manager is cleared between persist and query, then it returns the requested lock mode.
This happens also for entities without the
@Version
attribute: it always returnsPESSIMISTIC_FORCE_INCREMENT
, even if this lock mode is not supported by such entities.Executed queries, however, seem to be correct (“for update” query when pessimistic lock is requested, no “for update” query when optimistic / no lock is requested).
I have prepared a sample repository with exhaustive test cases: .
This issue starts from 6.6.0.Final.
By the way, in 6.4.x and 6.5.x, I also observed that:
requesting lock mode
NONE
always results intoOPTIMISTIC
/OPTIMISTIC_FORCE_INCREMENT
;requesting lock mode
OPTIMISTIC
without clearing entity manager results intoOPTIMISTIC_FORCE_INCREMENT
.