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.