-->
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.  [ 1 post ] 
Author Message
 Post subject: Random Error "Session is closed" when commiting
PostPosted: Mon Dec 02, 2013 5:18 pm 
Newbie

Joined: Mon Dec 02, 2013 1:32 pm
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.