-->
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: net.sf.hibernate.HibernateException: Session is closed
PostPosted: Fri May 19, 2006 10:33 am 
Newbie

Joined: Fri May 19, 2006 10:13 am
Posts: 3
Hello,

I have a weird problem with hibernate, i didn't find anything to help me, i hope to find some help or ideas here !

here is the code that bothers me :

Code:
try
{
   _RootDAO.initialize();
}
catch (HibernateException e)
{
   e.printStackTrace();
}
      
try
{
   Session session1 = UsersDAO.createSession() ;
   
   System.out.println("\nsession1.isConnected() = " + session1.isConnected());
   System.out.println("session1.isOpen() = " + session1.isOpen());
   
   session1.close();
   
   Session session2 = ExperiencesDAO.createSession() ;
   
   System.out.println("\nsession2.isConnected() = " + session2.isConnected());
   System.out.println("session2.isOpen() = " + session2.isOpen());
   
   session2.close();
}
catch (HibernateException e)
{
   e.printStackTrace();
}


so basically I open one session, close it and open a second. here is what i obtain :

Code:
session1.isConnected() = true
session1.isOpen() = true

session2.isConnected() = true
session2.isOpen() = false


I don't understand why the second session is not opened !!
when i try to do a query, for instance :

Code:
try
{
   Query q = session.getNamedQuery("user_email");
   q.setString(0, login);

   return q.list();
}
finally
{
   session.close();
}


the first time (with session1) it works fine, but the second time i obtain the following exception : (which i understand because session2 is actually closed)

Full stack trace of any exception that occurs:

net.sf.hibernate.HibernateException: Session is closed
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3292)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:65)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at bundle.DBAccess.getUserEmail(DBAccess.java:142)
at bundle.DBAccess.main(DBAccess.java:120)


I am very new to hibernate, so i'm sorry if this is a stupid error of mine, but i didn't find anything in the documentation of forum to help me...

thank you for any ideas, here is some additional information :

Hibernate synchronizer version: 2.3.1

Name and version of the database you are using: postgreSQL 8.1

sonia


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 3:45 am 
Newbie

Joined: Fri May 19, 2006 10:13 am
Posts: 3
no one has any suggestions ?? :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 6:30 am 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
Is the second session in reality the same as teh first???
That is does it use the same configuration?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 6:59 am 
Newbie

Joined: Fri May 19, 2006 10:13 am
Posts: 3
yes, i noticed a few hours ago that _BaseRootDAO returns me an existing session even if it's closed ! so yes actually i have twice the same session :)
i think that this is a "bug" or shortcoming of hibernate 2 because in hibernate 3 there is a method called createNewSession that really returns me a new session !
right now i'm trying to upgrade...

thanks for answering !


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.