Hi!,
I'm using Hibernate 3.5.5.Final and JPA2
How can make a testcase to test if the hibernate lock is working?
I wrote this, but seems that the test not pass in the current hibernate version (works fine in the previous version)
@Test(expected=OptimisticLockException.class)
public void testLock() {
EntityManager em = getEntityManager();
Foo foo1 = fooDAO.findById(1);
em.lock(foo1, LockModeType.WRITE);
foo1.setCode("code3");
em.flush();
}
EDIT:
@Pascal: that's what you mean in the second case?
@Test(expected=OptimisticLockException.class)
public void testLock() {
EntityManager em = getEntityManager();
em.getTransaction().begin();
Foo foo1 = fooDAO.findById(1);
em.lock(foo1, LockModeType.WRITE);
fooDAO.createHibernateQuery("update Foo set version=version+1 where id = 1");
foo1.setCode("code3");
em.flush();
}
Thanks