Hello,
My problem is that when I attempt to commit a transaction I get an HibernateException which states that my session has been closed. I'm using HibernateUtil from the "Hibernate in Action" book. I set a breakpoint in the HibernateUtil.commitTransaction() method and I can see that the tx (Transactions) session variables closed status is set to true. The session variable being used to perform database operations closed status is false.
What is closing the session for the tx object??
Hibernate version:
2.1.7
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Code:
Product product =
(Product)session.getAttribute(ProductAction.PRODUCT);
if(product != null) {
try {
// NOTE: creating a new ProductDAO() calls
// HibernateUtil.beginTransaction();
ProductDAO productDao = new ProductDAO();
Specifications spec = product.getSpecification(specId);
spec.setName(specsForm.getName());
spec.setDetail(specsForm.getDetail());
product.addSpecification(spec);
productDao.makePersistent(product);
HibernateUtil.commitTransaction();
} finally {
HibernateUtil.closeSession();
}
}
makePersistent() method of ProductDAO class
Code:
public void makePersistent(Product product)
throws InfrastructureException {
try {
HibernateUtil.getSession().saveOrUpdate(product);
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
}
Full stack trace of any exception that occurs:
net.sf.hibernate.HibernateException: Session is closed
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3327)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:63)
at com.myProject.util.HibernateUtil.commitTransaction(HibernateUtil.java:187)
at com.myProject.struts.action.SpecificationsAction.update(SpecificationsAction.java:139)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:276)
at org.apache.struts.actions.LookupDispatchAction.execute(LookupDispatchAction.java:162)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:731)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Name and version of the database you are using:
MySQL 4.0
Thanks,
c.