Good morning,
I have a problem in a project that is already in production. I am using Hibernate version 2.0.5
I have implemented the HibernateUtil class as detailed in the book "Hibernate in Action" (exactly the same class - copied and pasted)
This HibernateUtil class uses the ThreadLocal to store the session and the transaction object.
My commitTransaction method is as follows:
Code:
public void commitTransaction() throws InfrastructureException {
Transaction tx = (Transaction)threadTransaction.get();
try {
if ((tx != null) && (!tx.wasCommitted()) && (!tx.wasRolledBack())) {
tx.commit();
threadTransaction.set(null);
}
}
catch (HibernateException he) {
System.err.println("commitTransaction: ");
he.printStackTrace(System.err);
rollbackTransaction();
}
}
My problem is, that ramdonly, when calling this method I get a "Session is closed" exception, especifically when trying to commit my transaction (in the line tx.commit();)
Part of the stacktrace is as follows:
Code:
JDBCTransacti E net.sf.hibernate.transaction.JDBCTransaction toggleAutoCommit Could not toggle autocommit net.sf.hibernate.HibernateException: Session is closed at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3288) at net.sf.hibernate.transaction.JDBCTransaction.toggleAutoCommit(JDBCTransaction.java:104) at net.sf.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:95) at xxx.xxx.app.persistence.HibernateUtil.rollbackTransaction(HibernateUtil.java:122) at xx.xxx.app.persistence.HibernateUtil.commitTransaction(HibernateUtil.java:104) at
xx.xx..app.service.XXXService.getObjById(XXXService.java:241) a
I dont know what is going on, dont know if the ThreadLocal is failing for some reason, or if the Session is being closed by hibernate itself.
Please help