Multiple Hibernate transactions in a JTA session

510 views Asked by At

I would like to have multiple Hibernate transactions in a single EJB method call (running in WildFly). Currently my current_session_context_class is set to jta and transaction.factory_class is org.hibernate.transaction.JTATransactionFactory.

Now, for example, the following code fails:

public void myMethod(){
   try{
      Transaction tr = myHibernateSessionFactory.getCurrentSession().beginTransaction();
      //execute some DB operation
      tr.commit();

      tr = myHibernateSessionFactory.getCurrentSession().beginTransaction();
      //execute some DB operation
      tr.commit();

   }catch(Exception e){
      e.printStackTrace();
   }
}

The problem is that the second call to beginTransaction() throws an exception org.hibernate.TransactionException: Transaction instance is no longer valid.

How do I get a new transaction for the current session?

0

There are 0 answers