'What is the difference between TransactionManager.begin() and QuarkusTransaction.begin()?

Quarkus 2.8.0.Final introduced QuarkusTransaction. What is the difference between

@ApplicationScoped
public class MyClass {

    @Inject
    TransactionManager tm;

    public void doSomething() throws Exception {
        tm.begin();
        // ...
        tm.commit();
    }
}

and

@ApplicationScoped
public class MyClass {

    public void doSomething() {
        QuarkusTransaction.begin();
         // ...
        QuarkusTransaction.commit();
     }
}

?

I am using the TransactionManager in a lot of my tests, and when I replaced it with QuarkusTransaction, I am getting different error messages when something fails:

When using the TransactionManager, I am getting

javax.transaction.NotSupportedException: BaseTransaction.checkTransactionState - ARJUNA016051: thread is already associated with a transaction!

When using QuarkusTransaction, I am getting

javax.enterprise.context.ContextNotActiveException

The Quarkus documentation does not really explain why QuarkusTransaction was introcuded 🤔



Solution 1:[1]

QuarkusTransaction was introduced with this Pull Request and the idea is to provide an easier to use Transactions API.

As can be seen in this test, it's meant to be used when a request scope is active

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 geoand