-->
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.  [ 4 posts ] 
Author Message
 Post subject: UnresolvableObjectException: No row with the given identifie
PostPosted: Mon Jul 30, 2007 9:58 am 
Newbie

Joined: Mon Mar 20, 2006 6:23 am
Posts: 4
Hibernate version: 2.1.4

I have two entity classes:
EntityA and EntityB.
EntityA refer to EntityB as many-to-one.

1) I delete EntityB from Database (passing over hibernate)
2) I try to get EntityA
3) I get:
Code:
net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: 1, of class: EntityB


How I can avoid this exception. I want to get null instead of NPE.

Thanx.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 11:24 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
try using session.get(..) instead of session.load(...)

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 2:40 am 
Newbie

Joined: Mon Mar 20, 2006 6:23 am
Posts: 4
MikePloed wrote:
try using session.get(..) instead of session.load(...)

I'm using get(..) method


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 9:57 am 
Newbie

Joined: Sun Apr 09, 2006 8:38 am
Posts: 14
Don't you have a foreign key constraint on the column that holds the reference from EntityA to EntityB?

1. If you have it - then you can't delete EntityB without setting the column to
NULL.
Please note that there could be problems even with this approach, when using the second level cache.
(i.e the second level cache for entityA still holds a cached record, from when the instance held the relation to entityB,
but the instance that is referenced (of EntityB) is not in the cache -
hibernate will resolve entityA in the cache, and will try to load entityB from the database (cache miss) and will throw and ObjectNotFoundException.

I guess you can always catch:
try{
result = session.load(EntityA.Class, '123');

}catch(ObjectNotFoundException){
session.setCacheMode(CacheMode.REFRESH;
result = session.load(EntityA.Class, '123');
session.setCacheMode(CacheMode.NORMAL);
}

2. If you don't have a foreighn key constraint - I don't know a way to get rid of this problem. You really should set one...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.