org.hibernate.ObjectDeletedException: attempted to lock a deleted instance: [...]

Hibernate JIRA | Miguel Diaz | 5 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    When an entity is read using a read-only HQL query, if you run a Session.get() for that entity with LockOptions.UPGRADE you get a ObjectDeletedException. The reason of the failure is that the EntityEntry has status READ after the HQL query, and when the lock mode is upgraded in the Session.get(), AbstractLockUpgradeEventListener thinks that the READ status is wrong, throwing the ObjectDeletedException. I think that a READ_ONLY entity should be moved to MANAGED if you lock it. Or, otherwise, advice in the docs that a READ_ONLY entity can't be locked. Stacktrace: org.hibernate.ObjectDeletedException: attempted to lock a deleted instance: [...] at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:67) at org.hibernate.event.def.DefaultLoadEventListener.loadFromSessionCache(DefaultLoadEventListener.java:551) at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:440) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227) at org.hibernate.event.def.DefaultLoadEventListener.lockAndLoad(DefaultLoadEventListener.java:403) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:155) at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1081)

    Hibernate JIRA | 5 years ago | Miguel Diaz
    org.hibernate.ObjectDeletedException: attempted to lock a deleted instance: [...]
  2. 0

    When an entity is read using a read-only HQL query, if you run a Session.get() for that entity with LockOptions.UPGRADE you get a ObjectDeletedException. The reason of the failure is that the EntityEntry has status READ after the HQL query, and when the lock mode is upgraded in the Session.get(), AbstractLockUpgradeEventListener thinks that the READ status is wrong, throwing the ObjectDeletedException. I think that a READ_ONLY entity should be moved to MANAGED if you lock it. Or, otherwise, advice in the docs that a READ_ONLY entity can't be locked. Stacktrace: org.hibernate.ObjectDeletedException: attempted to lock a deleted instance: [...] at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:67) at org.hibernate.event.def.DefaultLoadEventListener.loadFromSessionCache(DefaultLoadEventListener.java:551) at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:440) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227) at org.hibernate.event.def.DefaultLoadEventListener.lockAndLoad(DefaultLoadEventListener.java:403) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:155) at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1081)

    Hibernate JIRA | 5 years ago | Miguel Diaz
    org.hibernate.ObjectDeletedException: attempted to lock a deleted instance: [...]

    Root Cause Analysis

    1. org.hibernate.ObjectDeletedException

      attempted to lock a deleted instance: [...]

      at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock()
    2. Hibernate
      SessionImpl.get
      1. org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:67)
      2. org.hibernate.event.def.DefaultLoadEventListener.loadFromSessionCache(DefaultLoadEventListener.java:551)
      3. org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:440)
      4. org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
      5. org.hibernate.event.def.DefaultLoadEventListener.lockAndLoad(DefaultLoadEventListener.java:403)
      6. org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:155)
      7. org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
      8. org.hibernate.impl.SessionImpl.get(SessionImpl.java:1081)
      8 frames