1

I've tried to find and update one record using pessimistic_write lock, like below,

transactionService.executeTransaction(() -> {
    Entity newEntity = em.find(entityClass, id, LockModeType.PESSIMISTIC_WRITE);
    newEntity = setEntityWithProperty.setEntity(newEntity, property);
});

I'm using the transactionTemplate in Spring.The entity itself has one version field to use the optimistic lock. With pessimistic_write lock, during the transaction (find and then update), other threads are supposed not able to read or write the record, right? But when commit the transaction, I can still get OptimisticLockFailuerException. Why this happens?

Man Shen
  • 401
  • 2
  • 16
  • due to the few facts known, I would suppose that `OptmisticLockException` *must* come from another entity... – xerx593 Feb 21 '19 at 21:19

0 Answers0