How to separate Hibernate Transaction from EJB one

I have migrated from WebSphere 8.5.5 with Hibernate 4.2 to JBoss EAP 7.1.5 + Hibernate 5.1.16. In WebSphere with Hibernate 4.2, I can separate Hibernate trasnaction from EJB one by using following coding. However, it does not work in JBoss EAP with Hibernate 5.1.16. In fact, I want commit data whatever associated EJB transaction is rollback/commit. Please help.

Source Code
session = HibernateManager.instance().getSessionFactory().openSession();
tx = session.beginTransaction();
session.save(accessLog);
tx.commit();
session.close();

You need to use Bean-Managed transactions in order to manually control the transaction outcome.

In a CMT, the application server manages the transaction, so you can only mark it for rollback.

Hi,

Thanks, can any other ways to separate tx in CMT as many codes have to change for BMT?

在 2018年12月3日週一 下午12:50,Vlad Mihalcea <hibernate@discoursemail.com 寫道:

You can use two different gateway EJB. One for CMT, the other for BMT. That’s how you can separate the flows.

HI,

I have checked our code, we have been implementing BMT. In fact, we would have to write database to record error when BMT transaction get problem. So, we want to commit it by using separated transaction inside BMT even BMT is rollback.

I think it is common requirement and Hibernate 3 & 4 are working.

In fact, we would have to write database to record error when BMT transaction get problem.

If the Tx failed, you can no longer use the same Hibernate Session, you need to start a new Session and Transaction.

So, we want to commit it by using separated transaction inside BMT even BMT is rollback.

You need to check the JBoss documentation or ask their forum for the best solution to this problem.

I think it is common requirement and Hibernate 3 & 4 are working.

Transaction handling happens in JBoss, so I don’t think this is a Hibernate issue. It worked with Hibernate 3 and 4 because you were using a different JBoss application server version.

Thanks for your kindly reply. Btw, I have solved the problem by setting Hibernate 5.1 configuration. For your information, I used JBoss 7.1.5 + Hibernate 4 is also OK before migrate to Hibernate 5.1.

It’s best if you describe exactly what configuration you changed to fix this issue.