-->
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.  [ 5 posts ] 
Author Message
 Post subject: How do I check if a Session is invalid after an exception?
PostPosted: Wed Dec 07, 2005 10:38 am 
Newbie

Joined: Wed Dec 07, 2005 10:20 am
Posts: 6
I use the threadlocal pattern to obtain a session via a Util class that manages the threadlocal session.

I would like to check the state of a session in the getSession() call before it is passed to the caller. If the session is invalid I would like to close the existing session, create a new Session and return this back to the caller.

Does any method in Session provide this state info for me?

thanks,
Rk


Top
 Profile  
 
 Post subject: Re: How do I check if a Session is invalid after an exceptio
PostPosted: Wed Dec 07, 2005 12:41 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Rk wrote:
I use the threadlocal pattern to obtain a session via a Util class that manages the threadlocal session.

I would like to check the state of a session in the getSession() call before it is passed to the caller. If the session is invalid I would like to close the existing session, create a new Session and return this back to the caller.

Does any method in Session provide this state info for me?

thanks,
Rk


Sessions are ALWAYS invalid after an exception.
http://www.hibernate.org/hib_docs/v3/re ... exceptions

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 11:19 pm 
Newbie

Joined: Wed Dec 07, 2005 10:20 am
Posts: 6
It looks like I did not clearly define my problem! Here is a example scenario I'm looking at

- code calls Util.getSession() to get a Hibernate Session. This is a threadlocal Session.

- db operation using this session throws an exception which is not caught anywhere except in the error handling layer further up the chain.

- Error handling layer logs all exceptions in a DB table and therefore calls Util.getSession() to write to the DB.
The problem is this session is invalid and ideally Util should be able to detect an invalid Session (to swap it for a new Session) before it attempts to pass it to the caller. It is the responsibility of the Util class to verify the validity of the Session.

Therefore, does Session or any other Hibernate class provide a way to check if the Session is invalid?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 11:21 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Rk wrote:
It looks like I did not clearly define my problem! Here is a example scenario I'm looking at

- code calls Util.getSession() to get a Hibernate Session. This is a threadlocal Session.

- db operation using this session throws an exception which is not caught anywhere except in the error handling layer further up the chain.

- Error handling layer logs all exceptions in a DB table and therefore calls Util.getSession() to write to the DB.
The problem is this session is invalid and ideally Util should be able to detect an invalid Session (to swap it for a new Session) before it attempts to pass it to the caller. It is the responsibility of the Util class to verify the validity of the Session.

Therefore, does Session or any other Hibernate class provide a way to check if the Session is invalid?


You'll need to code your error handling layer to deal with this. If you're "Handling" a HibernateException, then you need to discard the old session and create a new one.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 11:53 pm 
Newbie

Joined: Wed Dec 07, 2005 10:20 am
Posts: 6
Thanks for the info!

I was hoping that the Session would provide a way to detect invalid state. I'll perform this check in the erro handling layer then.


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