I would like to have confirmation of the following :
public void test() {
SomeEntity se = em.find(SomeEntity.class, 1);
// Do something...
se.setField = "test";
}
Here JPA will perform only optimistic check on se
.
Next :
public void test() {
SomeEntity se = em.find(SomeEntity.class, 1);
SomeOtherEntity soe = em.find(SomeOtherEntity.class, 1);
em.lock(soe, LockModeType.OPTIMISTIC);
// Do something...
se.setField = "test";
}
Here JPA will throw OptimisticException if se
OR soe
have been changed (version incremented in database) since last read.
Is that true ?
OptimisticLockException will be throw only when transaction commits to database ore you call
em.flush()
- then JPA Provider will compare version field and figure out that it was changed by another transactoin.