Hi,
I'll try to be more precise. I use hibernate-2.1, with an Oracle 8i database.
I did several tests, and here is what I can say.
To open and close sessions, I use the class HibernateUtil given in the hibernate distrib.
Here is the code, in a method where I pass a parameter value of type Object.
List result = null;
try {
// this is to use find method
String request = "from " + value.getClass().getName();
// this is to use criteria
Example example = Example.create(value);
net.sf.hibernate.Session session = HibernateUtil.currentSession();
// this work properly
result = session.find(request);
HibernateUtil.closeSession();
session = HibernateUtil.currentSession();
// this work properly
result = session.find(request);
HibernateUtil.closeSession();
session = HibernateUtil.currentSession();
// this throws an exception.
result = session.createCriteria(value.getClass()).add(example).list();
HibernateUtil.closeSession();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I can open and close sessions as long as I use the "find" method. I can't close a session if I want to use createCriteria: if one session has been closed, it throws an excpetion even if I get and open a new one. I can't figure out why.
The exception is this one and is thrown "after" the database has been queried.
net.sf.hibernate.JDBCException: SQLException occurred
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3443)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:177)
Caused by: java.sql.SQLException: Le flux de donn
|