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?