-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: "No row with the given identifier exists" Exception
PostPosted: Wed Jan 19, 2011 6:26 am 
Newbie

Joined: Tue Dec 06, 2005 10:13 am
Posts: 17
Hi,

I am in the process of upgrading to Hibernate 3.6 (from Hibernate 3.3).
Everything used to work good before the upgrade.
After the upgrade I started getting a: "No row with the given identifier exists" Exception.

This is the relevant part of the object (Named: Campaign):
------------------------------------------------------------------
@OneToOne(mappedBy = "campaign", optional = false)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@PrimaryKeyJoinColumn
private TargetDays targetDays;

This is the relevant inverse part of the other object (Named: TargetDays):
-----------------------------------------------------------------------------------
@OneToOne(optional=true)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@PrimaryKeyJoinColumn
private Campaign campaign;

This is the exception I am getting:
--------------------------------------
Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.todacell.ui.model.bo.campaign.TargetDays#756]
at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:433)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:233)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630)
at org.hibernate.type.EntityType.resolve(EntityType.java:438)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:982)
at org.hibernate.loader.Loader.doQuery(Loader.java:857)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3268)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
at com.todacell.ui.model.dao.BaseDAO.getObject(BaseDAO.java:62)
... 69 more
----------------------------------------------------------------------------------------------
Has anyone encountered similar problem?
Thanks in advance.


Top
 Profile  
 
 Post subject: Re: "No row with the given identifier exists" Exception
PostPosted: Tue Jul 19, 2011 4:05 pm 
Newbie

Joined: Thu Jul 14, 2011 11:36 am
Posts: 9
Faced the same issue.

It seems to me that the reason of the issue is the null check in org.hibernate.event.def.DefaultLoadEventListener.java
Code:
private Object returnNarrowedProxy(
         final LoadEvent event,
         final EntityPersister persister,
         final EntityKey keyToLoad,
         final LoadEventListener.LoadType options,
         final PersistenceContext persistenceContext,
         final Object proxy) {
      log.trace("entity proxy found in session cache");
      LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
      if ( li.isUnwrap() ) {
         return li.getImplementation();
      }
      Object impl = null;
      if ( !options.isAllowProxyCreation() ) {
         impl = load( event, persister, keyToLoad, options );
         if ( impl == null ) {
            event.getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( persister.getEntityName(), keyToLoad.getIdentifier());
         }
      }
      return persistenceContext.narrowProxy( proxy, persister, keyToLoad, impl );
   }


Method load( event, persister, keyToLoad, options ) checks returned proxy against null, but throws an exception only if null is not allowed
Quote:
protected Object load(
final LoadEvent event,
final EntityPersister persister,
final EntityKey keyToLoad,
final LoadEventListener.LoadType options) {

if ( event.getInstanceToLoad() != null ) {
if ( event.getSession().getPersistenceContext().getEntry( event.getInstanceToLoad() ) != null ) {
throw new PersistentObjectException(
"attempted to load into an instance that was already associated with the session: " +
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
);
}
persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), event.getSession() );
}

Object entity = doLoad(event, persister, keyToLoad, options);

boolean isOptionalInstance = event.getInstanceToLoad() != null;

if ( !options.isAllowNulls() || isOptionalInstance ) {
if ( entity == null ) {
event.getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( event.getEntityClassName(), event.getEntityId() );
}
}

if ( isOptionalInstance && entity != event.getInstanceToLoad() ) {
throw new NonUniqueObjectException( event.getEntityId(), event.getEntityClassName() );
}

return entity;
}


But returnNarrowedProxy does not check it and if the second method returns null - throws an exception for both GET and LOAD


Top
 Profile  
 
 Post subject: Re: "No row with the given identifier exists" Exception
PostPosted: Wed Jul 20, 2011 9:44 am 
Newbie

Joined: Thu Jul 14, 2011 11:36 am
Posts: 9
Fixed this issue by adding catch (ObjectNotFoundException e) to GET method implementation in Hibernate. I cannot find why Hibernate throws this exception for GET.

org.hibernate.impl.SessionImpl.java
Code:
public Object get(String entityName, Serializable id) throws HibernateException {
      LoadEvent event = new LoadEvent(id, entityName, false, this);
      boolean success = false;
      try {
         fireLoad(event, LoadEventListener.GET);
         success = true;
         return event.getResult();
      } catch (ObjectNotFoundException e) {
         //workaround for hibernate bug
         return null;
      } finally {
         afterOperation(success);
      }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.