When an entity has been locked within a transaction and later a standard refresh is invoked upon it this causes the EntityManager.getLockMode to return the standard OPTIMISTIC lock mode type (indicating not locked).
e.g. {code} // Read in some entity and validate getLockMode returns expected value Object entity = entityManager.find(EntityClass, entityId, LockModeType.PESSIMISTIC_WRITE); Assert.assertEquals(LockModeType.PESSIMISTIC_WRITE), entityManager.getLockMode(entity));
// This assert will now fail due to refresh entityManager.refresh(entity); Assert.assertEquals(LockModeType.PESSIMISTIC_WRITE), entityManager.getLockMode(entity)); {code}
A simple project has been included which illustrates this. |
|