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