hibernate / hibernate-demos

Repository for demos of various Hibernate projects
Apache License 2.0
282 stars 226 forks source link

ARJUNA017003 when using nested @Transactional(REQUIRES_NEW) in CdiJpaTest #49

Open duschata opened 2 years ago

duschata commented 2 years ago

Hello All, I've modified org.hibernate.demos.jpacditesting.CdiJpaTest a litte bit and I get an ARJUNA017003 Exception:

checking transaction and found that this connection is already associated with a different transaction! Obtain a new connection for this transaction.

https://github.com/duschata/hibernate-demos/blob/ARJUNA017003/other/cdi-jpa-testing/src/test/java/org/hibernate/demos/jpacditesting/CdiJpaTest.java#L156-L184

Works this as expected or is this a bug? How can I test my services which are annotated with REQUIRES_NEW?

Kind Regards Tom

alexxismachine commented 5 months ago

Even when I'm a little late at the party, I had the same problem.

I found https://developer.jboss.org/thread/280419 suggesting to use @TransactionScoped for the EntityManager produce method and it works for me.

Maybe you also need to set the isolation level. I did that in the getConnection method of the TransactionalConnectionProvider with e.g. com.arjuna.ats.jdbc.common.jdbcPropertyManager.getJDBCEnvironmentBean().setIsolationLevel( Connection.TRANSACTION_READ_COMMITTED);

Cheers Uli