Hi all,
I am getting an unexpected behaviour when using @Version that is only working with detached objects.
I have two concurrent requests that load the same persistent instance -therefore obtain the same version number-, modify some attributes and try to commit. I would expect the latest to throw an OptimisticLockException. However, both objects get committed unless I perform an evict.
Here is a test that shows it:
Code:
startNewTransaction();
this.setComplete();
Mortgage mortgage1 = basicController.find(Mortgage.class, 1);
mortgage1.setName("John");
mortgage1 = basicController.merge(mortgage1);
endTransaction();
startNewTransaction();
this.setComplete();
Mortgage mortgage2 = basicController.find(Mortgage.class, 1);
/*************
* This line is necessary to get an OptimisticLockException
*************/
//((Session)basicDAO.getEntityManager().getDelegate()).evict(mortgage2);
mortgage2.setName("David");
mortgage2.setVersion(0);
basicController.merge(mortgage2); // OptimisticLockException expected!!
endTransaction();
I was considering reporting this as a bug but wanted to get some feedback before.
Thanks in advance