-->
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: What happen is session is null ??
PostPosted: Sat Jan 31, 2004 12:46 pm 
Beginner
Beginner

Joined: Sun Dec 21, 2003 9:18 pm
Posts: 21
Okay when I read through Hibernate Documentation i found this piece of code : (Chapter 1 pg.6)

Code:

private static void closeSession() throws HibernateException {
logger.debug("CLOSING SESSION");

Session currSession = (Session) session.get();
session.set(null);

if (currSession != null) {
logger.debug("CURR SESSION != NULL");
try {
   currSession.close();
} catch (Exception err) {
   err.printStackTrace();
} finally {
   try
  {            
    currSession.close();
  }
  catch(HibernateException hibEx)
{
    throw hibEx;
  }
}
}
}


Well I added some extra debugging statement and try-catch..

Okay but here is my question :

1.Why does the code do session.set(null);
2. if currSession is null then how do we close the connection ??

Thanks for any hints,comment, or help ^____^


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2004 2:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is an example of the ThreadLocal Session pattern. Read http://www.hibernate.org/42.html and the Javadoc API for ThreadLocal


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.