Quote:
because in your catch block, you are trying to close the session
But I am trying to close the session in my finally block not in catch block.
try {
HibernateUtil.getSession();
HibernateUtil.beginTransaction();
// do 1st task
....
HibernateUtil.commitTransaction();
// call 2nd task
String returnMessage = ....
} catch (...) {
...
HibernateUtil.rollbackTransaction();
} finally {
System.out.println("Inside the finally block");
HibernateUtil.closeSession();
}
Quote:
Maybe put a try / catch around this (and ignore exception):
at com.pendylum.main.session.HibernateUtil.closeSession(HibernateUtil.java:134)
HibernateUtil is using ThreadLocal pattern. This is the method to close the Session:
public static void closeSession() {
try {
Session s = (Session)threadSession.get();
threadSession.set( null );
if ( s != null && s.isOpen() ) {
System.out.println( "HibernateUtil: Closing Session of this thread." );
s.close();
System.out.println( "HibernateUtil: closeSession() successfully executed." );
}
} catch ( HibernateException hex ) {
System.out.println( "HibernateUtil: closeSession() failed." );
hex.printStackTrace();
}
}
The line 134 is :
s.close();
As you can see I already have a try and catch block. Any suggestion?
Thanks
Uryl