Hibernate StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

Solution Verified - Updated -

Issue

  • Clustering has been configured for multiple server JVMs
  • Level 2 caching is enabled for persistence units deployed in each server
  • When entities are concurrently updated in multiple server JVMs, some JVMs encounter repeated StaleObjectStateException failures for specific entities

    • Affected entities remain in the level 2 cache until they are explicitly or implicitly (e.g. due to timeout) evicted

      org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.abc.domain.entitity.ObjectA#123456]
          at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1782)
          at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2425)
          at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2325)
          at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2625)
          at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
          at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:278)
          at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:262)
          at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
          at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
          at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)
          at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:999)
          at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1185)
          at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
          at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:116)
          ...
      

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 5
    • 6
  • Hibernate
    • Hibernate 3 / JBossCache
    • Hibernate 4 / Infinispan

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In