1 Reply Latest reply on Dec 21, 2004 1:12 PM by Emily

    rollback problems using HibernateContext for session managem

    Emily Newbie

      I am seeing "unclosed connection" messages when I rollback transactions. Tracing through the TransactionManager and Hibernate classes, I do not see Hibernate sessions being closed when rollback is called on a transaction, only when commit is called().

      I am using HibernateContext to manage my sessions. I begin a transaction and get the Hibernate session using a utility method i created that looks like this

      
      public static net.sf.hibernate.Session getSession() throws InfrastructureException{
      
       try{
       TransactionManager tm = getTransactionManager();
       if( tm.getTransaction() == null)
       {
       tm.begin();
       }
      
       Session session = HibernateContext.getSession("java:/HibernateFactory");
      
       return session;
      
       }catch(Exception e)
       {
       throw new InfrastructureException(e);
       }
       }
      
      


      When I commit transactions, everything is fine. However when I rollback transactions, I see unclosed connection statements. I looked through the jboss and hibernate code, and it looks like the hibernate
      session.close() method is called from jboss' TransactionSynch.beforeCompletion() method which in turn is called from
      TransactionImpl.doBeforeCompletion()
      TransactionImpl.doBeforePrepare()
      TransactionImpl.commit();

      I do not see hibernate sessions being closed anywhere else in the code, which I assume is why I am seeing unclosed connection messages when I commit. What am I missing here?

      Thanks,
      Emily


        • 1. Re: rollback problems using HibernateContext for session man
          Emily Newbie

          I changed my code to use UserTransactions, before anyone complains about that. I am still seeing unclosed connections.

          public static net.sf.hibernate.Session getSession() throws InfrastructureException{
          
           try{
           UserTransaction tm = getTransactionManager();
           if(tm.getStatus() == Status.STATUS_NO_TRANSACTION)
           tm.begin();
          
           Session session = HibernateContext.getSession("java:/HibernateFactory");
          
           return session;
          
          
           }catch(Exception e)
           {
           throw new InfrastructureException(e);
           }
           }