Announcement Announcement Module
Collapse
No announcement yet.
Hibernate updates version on read OptimisticLockingException StaleobjectException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate updates version on read OptimisticLockingException StaleobjectException

    Hi,

    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,
    Chandan
    Last edited by chandankhatri; Jan 14th, 2013, 12:27 PM.
Working...
X