Jan 14th, 2013, 11:23 AM
Hibernate updates version on read OptimisticLockingException StaleobjectException
I am facing a problem that is related to OptimisticLocking exception nested with StaleObjectStateException. This is occurring when i m reading a versioned entity from DB under @transaction context.
I found that there is an open bug in Hibernate Jira https://hibernate.onjira.com/browse/HHH-5867
which states ---->
On a special constellation hibernate increases the internal used version of an entity on a read operation. For example if you save an entity the version is initial set. If you execute a query to read the entity afterwards, the version increases on this read. Please notice that the entity has NOT changed in the meantime. An update of the version must not happen here.
This problem seems to occur only if you have a few prequisites:
1. An entity, which has a component or subclasses
2. The component/subclasses must use an custom usertype
3. The read operation is covered by transaction -----> This is my case.
The bug leads to StaleObjectStateExceptions in production because the version has changed after a read operation by another thread.
The issue i am facing now is my service layer is annotated with @Transactional to avoid LazyInitializationException and due to this Transaction the version number of the entity is getting updated on every read operation.
I would really appreciate your suggestion/comments on this. This is an issue in production so please help me.
Thanks and regards,
Last edited by chandankhatri; Jan 14th, 2013 at 11:27 AM.
Tags for this Thread