javaspring-data-jpatransactionsjtaatomikos

Atomikos library has incompatibility packages (from javax.transaction to jakarta.transaction)


I have Atomikos (6.0.0) in Spring Boot 3 and using Java 21. It's working but using a @Deprecated class, "ChainedTransactionManager(transactionManagerOne, transactionManagerTwo)". This way shows me a lot of warnings that I don't like and I want to use the recommended way.

This are the libraries i'm using in my pom.xml

    <dependency>
        <groupId>com.atomikos</groupId>
        <artifactId>transactions-jdbc</artifactId>
        <version>6.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.atomikos</groupId>
        <artifactId>transactions-jta</artifactId>
        <version>6.0.0</version>
    </dependency>

Looking everywhere, tells me to use this:

@Bean
public UserTransaction userTransaction() {
   //uses javax.transaction.*
    return new UserTransactionImp();
}

@Bean(initMethod = "init", destroyMethod = "close")
public TransactionManager transactionManager() {
   //uses javax.transaction.*
    return new UserTransactionManager(); 
}

@Bean
public PlatformTransactionManager platformTransactionManager() throws Throwable {
    //using jakarta.transaction.*
    return new JtaTransactionManager(userTransaction(), transactionManager());
}

But my problem is that the object JtaTransactionManager is from the new spring-tx-6.1.6 which uses jakarta.transaction.UserTransaction and jakarta.transaction.TransactionManager objects, but the objects new UserTransactionImp() and new UserTransactionManager() are using the old way, with javax.transaction.UserTransaction and javax.transaction.TransactionManager used in the JAR transaction-jta-6.0.0.

How can I make new UserTransactionImp() and new UserTransactionManager() compatible with jakarta.transaction.*?


Solution

  • How are you importing Atomikos in your project? Using the starter:

    <dependency>
      <groupId>com.atomikos</groupId>
      <artifactId>transactions-spring-boot3-starter</artifactId>
      <version>6.0.0</version>
    </dependency>
    

    I notice that transaction-jdbc, transaction-jms and transaction-jta are automatically imported with jakarta as classifier, thus having transaction-jdbc-6.0.0-jakarta.jar and so on in classpath.

    Looking in the repository directory (https://repo1.maven.org/maven2/com/atomikos/transactions-jta/6.0.0/) in fact there are two different jars.

    Check if you are importing the "no-jakarta" modules, and in this case try to use the starter, or specify the classifier in pom.xml, like this:

    <dependency>
      <groupId>com.atomikos</groupId>
      <artifactId>transactions-jta</artifactId>
      <version>6.0.0</version>
      <classifier>jakarta</classifier>
    </dependency>
    

    Please see also this other question / answer: Failed to convert atomikos J2eeTransactionManager to required type jakarta TransactionManager