-->
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: Must discard Session if lock acquisition fails?
PostPosted: Wed May 12, 2004 5:54 pm 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
The Hibernate manual states that Sessions should be discarded when an exception is thrown:

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.


Does this apply when an attempt to acquire a lock fails?

Code:
// re-attach a detached object
aSession.lock(anObject, LockMode.NONE);


I'd like to continue using Sessions after lock acquisition failures under a variety of circumstances. The most mundane example is using lock() to do a version check. Same for attempting to acquire a pessimistic lock with NOWAIT.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 10:46 pm 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
Come to think of it, I have the same question about Session.get() and Session.load() -- can I continue to use the Session if it throws an exception because no object was found with the specified ID?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 5:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes, you can reuse the session after an ObjectNotFoundException. I won't rely on it after a lock failure though.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 12:18 pm 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
Thanks for the reply.

Does this apply when the "lock" is just a version check?

Code:
SELECT ... FROM ... WHERE id=? AND version=?

I use long-lived/disconnect Sessions, and would like to refresh or evict the stale object rather than discarding the entire Session. I understand that there may be other inconsistencies (e.g., stale data) in the Session cache that could bite me later, but that's always a risk with long-lived Sessions.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.