Hi All,
I'm running an EJB application in WildFly in which I use Hibernate. All have been working just fine, but now I stumbled to a problem, when I wan't to have two transactions in one method call (ie. the second transaction is a long running one, and I want to commit the first transaction before the start of the long running process)
So, my code is like this:
Code:
public void myMethod(){
try{
Transaction tr = HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
//execute some DB operation
tr.commit();
tr = HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
//execute some DB operation
tr.commit();
}catch(Exception e){
e.printStackTrace();
}
}
The second call to beginTransaction() throws
org.hibernate.TransactionException: Transaction instance is no longer valid. What is actually causing this and how can I go around it?
I have set
current_session_context_class to
JTA and
transaction.factory_class to
org.hibernate.transaction.JTATransactionFactory in hibernate.cfg.xml