-->
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.  [ 3 posts ] 
Author Message
 Post subject: What to do when SessionFactory.getCurrentSession() is closed
PostPosted: Wed Jun 08, 2011 5:09 pm 
Newbie

Joined: Mon Jun 22, 2009 12:11 pm
Posts: 5
Hello,

I am getting the exception "org.hibernate.SessionException: Session is closed!" intermittently in a production environment when trying to get the Transaction via:

Session session = sessionFactory.getCurrentSession();
Transaction transaction = session.getTransaction();

So far I am unable to reproduce this error on a developer machine unless I specifically close out the session with session.close(), however I cannot find any instances of something like that in the code. I'd like to be able to test to see if session is open or not--if it's not, I'd like to open a session, however I'd like to continue to have Hibernate manage the connections, so I'm hesitant to use SessionFactory.openSession().

Is there a way to get a new session and tie it back into Hibernate for mangement, in the case where SessionFactory.getCurrentSession() returns a closed session?

Thanks so much,
Pedro


Top
 Profile  
 
 Post subject: Re: What to do when SessionFactory.getCurrentSession() is closed
PostPosted: Thu Jun 09, 2011 12:37 am 
Newbie

Joined: Mon Jun 22, 2009 12:11 pm
Posts: 5
In hopes of getting someone to reply, here's what I'm looking for code-wise:

try {
if (!isInitialized) {
init();
}

long start = System.currentTimeMillis();
Session session = sessionFactory.getCurrentSession();

if (!session.isOpen()) {
//SOMEHOW RE-OPEN THE SESSION AND TIE IT BACK INTO HIBERNATE FOR CONNECTION MANAGEMENT

}

//This line is capable of throwing a "session is already closed!" exception
Transaction transaction = session.getTransaction();

Thanks,
Pedro


Top
 Profile  
 
 Post subject: Re: What to do when SessionFactory.getCurrentSession() is closed
PostPosted: Fri Feb 03, 2012 6:05 am 
Newbie

Joined: Sun Oct 11, 2009 7:17 pm
Posts: 8
Quote:
//SOMEHOW RE-OPEN THE SESSION AND TIE IT BACK INTO HIBERNATE FOR CONNECTION MANAGEMENT


Did you work out how to do this?

_________________
Kremsoft
Software Development Outsourcing http://www.kremsoft.com


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