-->
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: Session.load() or Session.find() for existence
PostPosted: Sun Nov 09, 2003 4:20 pm 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
In the docs in order to determine if an instance with the given identifier exists on the database it's better to use find() than load().

Can someone please explain to me why?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2003 5:55 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
I think it is because find() does not throw exception in the case when object with given ID does not exist.

Of course, you can catch exception and handle it appropriately, but "appropriately" here means:

"If the Session throws an exception (including any SQLException), you should immediately rollback the transaction, call Session.close() and discard the Session instance." (7.9.4. Exception handling)

PS: With Hibernate 2.1 there is even better method - session.get()


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2003 7:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Remember that load() can return an uninitialized proxy.


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.