1

I have a class file, CBRTask.java

In this CBRTask.java, I have some code as follow:

@Autowired
private CbrService cbrService;

public CBRPayment execute() {

   try {
        cbrService.sendCR( this.entity );
        // If I manually throw Exception here, no problem in catch
   catch (Exception exception) {
   // do something to call db, but hit error
   }
}

And then In my CbrService class:

I throw exception

throw new Exception();

Then this will catch in CBRTask.java, and then cause the db calling hit error.

Suppose it should not happen. Because this code is working fine in Hibernate 3. After I migrate to hibernate 5, then only hit.

Here is the error log:

org.hibernate.HibernateException: Current transaction is not in progress
    at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:81)
    at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:721)

And if I manually throw the Exception in CBRPayment class, and catch in the same place, the problem wont happen.

Panadol Chong
  • 1,793
  • 13
  • 54
  • 119
  • Could you also show the content of the class `CBRTask`? Because in general, this message means that you want to retrieve the current session with no available transaction. This can have multiple reasons (e.g. no transaction was ever started, it was already rolled back, ...). I guess the code of the service would be helpful. I could think of the following: Perhaps you are already rolling back the transaction in the service, and after you want to invoke another db call on the task-class, you get the aforementioned error. – Michael Altenburger Sep 21 '18 at 06:08
  • Check that your class `CbrService` has an _@Transaction_ annotation upon it, or your `sendCR(..)` method if you prefer. If the annotation already exist, search for other logs entries before this failure, like Michael said. Something happened before. – Marc Le Bihan Sep 21 '18 at 09:36

1 Answers1

0

Its actually not because of upgrading of Hibernate 3 to Hibernate 5. But its about the transaction manager. Before this, I was using WebSphereUowTransactionManager, where this thing will auto creating new transaction everytime after catch an exception.

When I come to Jboss environment, I am using JTATransactionManager, not sure why this manager will using back the existing transaction even there is a transaction being catch.

What I do is, change the GlobalRollbackOnParticipationFailure to false.

Panadol Chong
  • 1,793
  • 13
  • 54
  • 119