-->
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: When must Sessions be discarded?
PostPosted: Fri Aug 13, 2004 2:30 pm 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
From the Hibernate manual:

Quote:
If the Session throws an exception (including any SQLException), you should immediately rollback the transaction, call Session.close() and discard the Session instance. Certain methods of Session will not leave the session in a consistent state.

Is this the most definitive statement that the Hibernate team can make regarding exception handling? Is it always necessary to discard the Session on any exception?

I was told in another thread that I don't need to discard the Session after an ObjectNotFoundException.

I understand well why a Session needs to be discarded when a transaction commit fails or there's a SqlException or JdbcException. But I don't understand why errors stemming from lock failures or stale data should require the Session to be discarded, especially when the operation was read-only (and did not trigger a Session flush).

In short: which methods/exception leave the Session in an invalid state and require it to be discarded?

- ObjectNotFoundException
- ObjectDeletedException
- StaleObjectStateException
- TransientDataException

p.s. I glanced through my electronic preview of Hibernate in Action, and did not see where this was addressed.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 4:21 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
I just scanned through the Hibernate Code for all places where an ObjectNotFoundException is thrown. AFAIK you can savely go on with your Session/Transaction after catching a ObjectNotFoundException for theses methods:

Code:
public Object load(Class clazz, Serializable id) throws HibernateException;
public Object load(Class clazz, Serializable id, LockMode lockMode) throws HibernateException;
public void load(Object object, Serializable id) throws HibernateException


HTH
Ernst


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.