-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem calling Hibernate.initialize 2nd time w/Lazy Loading
PostPosted: Tue May 01, 2007 10:00 am 
Newbie

Joined: Tue May 01, 2007 9:20 am
Posts: 1
Hibernate version: 3.1.2

We are upgrading from Hib2 to Hib3 and have run into an issue when calling Hibernate.initialize. In this case our entity does not exist in the database but because we are lazy loading the session.load() still returns a proxy. The first call to initialize() throws an ObjectNotFoundException as expected. The second call however does not throw the ObjectNotFoundException even though the entity still doesn't exist.

While debugging through AbstractLazyInitializer.initialize() I found the first call sets an initialized flag, prior to throwing the ObjectNotFoundException. The second call sees the initialized flag is set which prevents the immediateLoad, and therefore prevents the ObjectNotFoundException on the second call.

We can work around this problem by evicting the proxy from the session after the first ObjectNotFoundException, but is this functioning as designed or bug that needs reporting?

_________________
Doug Bender


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 01, 2007 2:17 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
From section 10.3 of the Hibernate 3.2.3 manual:

Quote:
If you are not certain that a matching row exists, you should use the get() method, which hits the database immediately and returns null if there is no matching row.


get() will give you null if the row doesn't exist. You can check for that and handle appropriately.

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.