org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [...] when using @NotFound(IGNORE)

Solution Verified - Updated -

Issue

  • An entity is defined with an EAGER ManyToOne association (foreign key) which is annotated with @NotFound(IGNORE).
    • A non-null value (e.g. 1234) is stored in the underlying database for the foreign key column.
    • In the table for the One ("primary key") side of the association (e.g. the table for an Employee entity) there is no row that corresponds to the foreign key reference (e.g. no "Employee" primary key has the value 1234).
    • Referential integrity was disabled in the backing datasource to allow storage of inconsistent data.
  • When loading the entity with the non-resolvable foreign key (the Many side), an exception is sometimes encountered (the failure may not always occur).

    ... org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [support.hibernate.entity.Employee#12345]
        at org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:247)
        at org.hibernate.event.internal.DefaultLoadEventListener.returnNarrowedProxy(DefaultLoadEventListener.java:295)
        at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:256)
        at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
        at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1053)
        at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:980)
        at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:714)
        at org.hibernate.type.EntityType.resolve(EntityType.java:502)
        at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:168)
        at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:137)
        at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1140)
        at org.hibernate.loader.Loader.processResultSet(Loader.java:968)
        at org.hibernate.loader.Loader.doQuery(Loader.java:916)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:347)
        at org.hibernate.loader.Loader.doList(Loader.java:2578)
        at org.hibernate.loader.Loader.doList(Loader.java:2564)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2394)
        at org.hibernate.loader.Loader.list(Loader.java:2389)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:357)
        at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:198)
        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1230)
        at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
    

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 7
    • 6
  • Hibernate (legacy/non-JPA)
    • 5
    • 4

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content