org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.hrs.frw.jpa.flux.test.entities.RelationTwo#RelationId{idNumber=31, idString='x1'}]

Hibernate JIRA | Robert Stupp | 4 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    Assume the following: Two entity types: RelationOne @ManyToOne @NotFound(IGNORE) RelationTwo relationTwo; RelationTwo (nothing special) Further: insert one instance of RelationTwo insert two instances of RelationOne, which reference RelationTwo Next step: commit Next: new Session & TX Load RelationOne (Session.get()) Delete RelationOne (Session.delete()) commit Next: new Session & TX Load one instance of RelationTwo (everything is fine) Load next instance of RelationTwo (FAILURE) {noformat} org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.hrs.frw.jpa.flux.test.entities.RelationTwo#RelationId{idNumber=31, idString='x1'}] at org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:242) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:210) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:260) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1075) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1002) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:613) at org.hibernate.type.EntityType.resolve(EntityType.java:441) at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:168) at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:134) at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:999) at org.hibernate.loader.Loader.doQuery(Loader.java:878) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:263) at org.hibernate.loader.Loader.loadEntity(Loader.java:1977) {noformat} {{org.hibernate.event.internal.DefaultLoadEventListener#proxyOrLoad}} contains the following code: {noformat} // look for a proxy Object proxy = persistenceContext.getProxy(keyToLoad); if (proxy != null) { return returnNarrowedProxy(event, persister, keyToLoad, options, persistenceContext, proxy); } if (options.isAllowProxyCreation()) { return createProxyIfNecessary(event, persister, keyToLoad, options, persistenceContext); } // return a newly loaded object return load(event, persister, keyToLoad, options); {noformat} The load of the first instance of RelationTwo has a {{null}} proxy variable for RelationOne, but the second load of RelationTwo has a non-null proxy variable for RelationOne. This results in a call to {{org.hibernate.event.internal.DefaultLoadEventListener#load}} which unconditionally raises an {{ObjectNotFound}} exception.

    Hibernate JIRA | 4 years ago | Robert Stupp
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.hrs.frw.jpa.flux.test.entities.RelationTwo#RelationId{idNumber=31, idString='x1'}]
  2. 0

    Assume the following: Two entity types: RelationOne @ManyToOne @NotFound(IGNORE) RelationTwo relationTwo; RelationTwo (nothing special) Further: insert one instance of RelationTwo insert two instances of RelationOne, which reference RelationTwo Next step: commit Next: new Session & TX Load RelationOne (Session.get()) Delete RelationOne (Session.delete()) commit Next: new Session & TX Load one instance of RelationTwo (everything is fine) Load next instance of RelationTwo (FAILURE) {noformat} org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.hrs.frw.jpa.flux.test.entities.RelationTwo#RelationId{idNumber=31, idString='x1'}] at org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:242) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:210) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:260) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1075) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1002) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:613) at org.hibernate.type.EntityType.resolve(EntityType.java:441) at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:168) at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:134) at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:999) at org.hibernate.loader.Loader.doQuery(Loader.java:878) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:263) at org.hibernate.loader.Loader.loadEntity(Loader.java:1977) {noformat} {{org.hibernate.event.internal.DefaultLoadEventListener#proxyOrLoad}} contains the following code: {noformat} // look for a proxy Object proxy = persistenceContext.getProxy(keyToLoad); if (proxy != null) { return returnNarrowedProxy(event, persister, keyToLoad, options, persistenceContext, proxy); } if (options.isAllowProxyCreation()) { return createProxyIfNecessary(event, persister, keyToLoad, options, persistenceContext); } // return a newly loaded object return load(event, persister, keyToLoad, options); {noformat} The load of the first instance of RelationTwo has a {{null}} proxy variable for RelationOne, but the second load of RelationTwo has a non-null proxy variable for RelationOne. This results in a call to {{org.hibernate.event.internal.DefaultLoadEventListener#load}} which unconditionally raises an {{ObjectNotFound}} exception.

    Hibernate JIRA | 4 years ago | Robert Stupp
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.hrs.frw.jpa.flux.test.entities.RelationTwo#RelationId{idNumber=31, idString='x1'}]

    Root Cause Analysis

    1. org.hibernate.ObjectNotFoundException

      No row with the given identifier exists: [com.hrs.frw.jpa.flux.test.entities.RelationTwo#RelationId{idNumber=31, idString='x1'}]

      at org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound()
    2. Hibernate
      Loader.loadEntity
      1. org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:242)
      2. org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:210)
      3. org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:260)
      4. org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148)
      5. org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1075)
      6. org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1002)
      7. org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:613)
      8. org.hibernate.type.EntityType.resolve(EntityType.java:441)
      9. org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:168)
      10. org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:134)
      11. org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:999)
      12. org.hibernate.loader.Loader.doQuery(Loader.java:878)
      13. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293)
      14. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:263)
      15. org.hibernate.loader.Loader.loadEntity(Loader.java:1977)
      15 frames