Hello everyone,
I am using Hibernate 4.1.4 as a JPA 2.x provider, within JBoss 7.1 using EJB 3.0 stateless session beans.
I have a JPA mapped entity that has been in use for some time in our application and works fine. I am attempting to change the entity to introduce an instance variable that bears the javax.persistence.Version annotation. This works fine, but I cannot get em.lock(object, LockModeType.OPTIMISTIC_FORCE_INCREMENT) to throw an OptimisticLockException as I find in the javadoc comments for EntityManager. In the broader sense, when I execute end user use cases that I would expect to induce an OptimisticLockException to occur, none are raised. So, I am trying to determine if my code is missing something, or if I have stumbled upon a defect in Hibernate 4.1.4. In my reading of the release notes in subsequent Hibernate versions, I do not find a defect noted that is what I am seeing.
So, lets say my JPA mapped entity looks like the following :
public class A { // pre-existing instance variables here omitted for brevity.
@Version private int readVersion;
// Methods omitted for brevity
public int getReadVersion() { return readVersion; } public void setReadVersion(int newValue) { readVersion = newValue; } }
Now say I do the following in an EJB 3.0 stateless session bean method that by default will use transaction attribute type of REQUIRED for container managed transaction :
A a = em.find(A.class, someId); a.setReadVersion(5); // Even though readVersion in the database is say 12, just trying to force an OptimisticLockException em.lock(a, LockModeType.OPTIMISTIC_FORCE_INCREMENT); // Should throw OptimisticLockException right now correct?
I do not see an exception thrown from the em.lock() call, and there is a call to em.flush() a few lines later and it does not raise an OptimisticLockException either.
Do you have an idea of how my code should be different so that Hibernate will in fact raise an OptimisticLockException or if this is a known issue or if it is known and addressed subsequent to Hibernate 4.1.4?
Thanks,
Doug
|