-->
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: disconnectSession(), HibernateUtil example
PostPosted: Wed Jun 08, 2005 2:00 pm 
Newbie

Joined: Fri May 06, 2005 6:04 pm
Posts: 11
Location: ES - Brazil
Hi,

This is the code for the disconnectSession() at HibernateUtil in the latest CaveatEmptor example.

Code:
public static Session disconnectSession()
   throws InfrastructureException {

   Session session = getSession();
   try {
      threadSession.set(null);
      if (session.isConnected() && session.isOpen())
         session.disconnect();
   } catch (HibernateException ex) {
      throw new InfrastructureException(ex);
   }
   return session;
}


My question is, instead of threadSession.set(null), shouldn´t be


Code:
try {
   if (session.isConnected() && session.isOpen())
   {
      session.disconnect();
      threadSession.set(session);
   }
} catch ...
   



Because if it is threadSession.set(null), when we call the getSession, it will open a new session.

I don´t know if I missed something, but it is what I understood when you sugested the disconect() for the Long session at the Hibernate in action...

Thank you in advance
Pedro Henrique


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 2:04 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You simply don't call getSession() after disconnectSession() without doing a reconnectSession() first. You have to null out the threadlocal variable.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 1:32 pm 
Newbie

Joined: Fri May 06, 2005 6:04 pm
Posts: 11
Location: ES - Brazil
Thanks for the quick reply Christian.

That was what i was missing ...


About this:

Quote:
You have to null out the threadlocal variable.


Why do I have to null out the threadlocal variable? I mean in your example I see why, because the way you work with the reconnection. But what about if I want to make the reconnect(), reconect the session from the ThreadLocal variable, and the disconnect() disconect this session but not null out the variable , wich would only be done when I call closeSession().It would be a problem?

Thanks again.
Pedro Henrique


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 4:39 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I don't know what you want.


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.