How to resolve HibernateObjectRetrievalFailureException (org.hibernate.ObjectNotFoundException: No row with the given identifier exists exception)?


Quite recently, we were getting the below exception in one of our stand-alone java application:

org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException: No row with the given identifier exists: [example.hibernate.pojo.Person#10878]; nested exception is org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [example.hibernate.pojo.Person#10878]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:660)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.loadAll(HibernateTemplate.java:595)
. . .
Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [example.hibernate.pojo.Person#10878]
at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:386)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:145)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:179)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:879)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:847)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:567)
at org.hibernate.type.EntityType.resolve(EntityType.java:389)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:120)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2217)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2108)
at org.hibernate.loader.Loader.list(Loader.java:2103)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1570)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.springframework.orm.hibernate3.HibernateTemplate$5.doInHibernate(HibernateTemplate.java:600)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
… 7 more

 

Here’s what we did to solve it:

We added not-found=”ignore” to the association mapping in the hibernate configuration for Person POJO.

Eg.

<class name=”Person”>
    <id name=”id” column=”personId”>
        <generator/>
    </id>
    <many-to-one name=”address”
        column=”addressId”
        unique=”true”
        not-null=”true”
        not-found=”ignore”/>
</class>

This’ll solve the issue, but we need to research about this a bit at Database level – why a row that was expected to be present was’t – as it may lead to functional issues at a later point of time.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 26 other followers

%d bloggers like this: