-->
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.  [ 6 posts ] 
Author Message
 Post subject: Sporadic "Session is currently disconnected" excep
PostPosted: Thu Jan 08, 2004 5:27 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
I am occaisionally getting:

net.sf.hibernate.HibernateException: Session is currently disconnected

exceptions. The code works most of the time, but if I repeatedly refresh a page from my web app, the Hibernate code occaisionally throws this exception.

Why does this occur?

Thanks,
Kevin Hooke


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 6:59 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
What database and JDBC driver are you using?

In my experience this exception is usually caused by either 1) underlying JDBC driver or DB dropping connection (had lots of problems with MySQL) or, 2) connection pooling gone bad.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 9:50 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
DB2 8.1 on Windows XP, with the JDBC driver that comes with this version of DB2.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 1:41 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
Why is the session disconnected?

After each interaction from the web frontend via a Struts Action interacting with a DAO class wrapping the Hibernate code, I call close on the Session.

I am expecting that each new request from the web client will use a new Session, therefore I am confused as to why Hibernate thinks it is disconnected?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 3:05 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
I was having a possibly similar problem a while ago, so put in some code to compensate. I haven't had the problem in a while, but I left the code in just in case. :)

Code:
SessionImplementor session = (SessionImplementor)factory.openSession();

try {

    //Guard against stale JDBC connections and bad connection pools
    while(!session.isConnected() || session.connection().isClosed()) {
    LOG.warn("New session reconnect!");
    session.reconnect();

    }
} catch(SQLException sqle) {
    sqle.printStackTrace();
}


Top
 Profile  
 
 Post subject: Fixed!
PostPosted: Fri Jan 09, 2004 3:47 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
Thanks for that code.

I worked out what was going wrong. I am using a Utils class that creates the Sessions and handles closing etc (similar to the example in the manual).

The Session that was returned from my Utils class I was explicitly closing in my DAO code, rather than calling the closeSession() method on my Utils class to close the session. Therefore next time I called getSession() on my Utils class it was returning the old/previous Session in a closed/disconnected state...

Looks like everything is working pretty well now... looks pretty fast too :-)

Thanks,
Kevin Hooke


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