Skip to content
Advertisement

OpenLiberty JakartaEE 9: access TransactionManager

On Docker Image open-liberty:22.0.0.1-full-java17-openj9 with the following activated features:

<featureManager>
  <feature>persistence-3.0</feature>
  <feature>localConnector-1.0</feature>
  <feature>microProfile-5.0</feature>
  <feature>beanValidation-3.0</feature>
</featureManager>

and the javax namespace, it was possible to create an TransactionManager via the api dependency

  compileOnly "com.ibm.websphere.appserver.api:com.ibm.websphere.appserver.api.transaction:1.1.60"

in the following way:

package de.xxx.xxx;

import com.ibm.tx.jta.TransactionManagerFactory;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.transaction.TransactionManager;

@RequestScoped
public class TransactionManagerProducer {

@Produces
 public TransactionManager produce() {
  return TransactionManagerFactory.getTransactionManager();
 }
}

We are moving to JakartaEE9 and this one API dependency seems not to have an equivalent for the jakarta.* namespace, so that this is not compiling:

package de.xxx.xxx;

import com.ibm.tx.jta.TransactionManagerFactory;
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.transaction.TransactionManager;

@RequestScoped
public class TransactionManagerProducer {

@Produces
 public TransactionManager produce() {
  return TransactionManagerFactory.getTransactionManager();
 }
}

In the openliberty zip, see https://repo1.maven.org/maven2/io/openliberty/openliberty-runtime/22.0.0.1/openliberty-runtime-22.0.0.1.zip an equivalent implementation for

wlpdevapiibmcom.ibm.websphere.appserver.api.transaction_1.1.60.jar  (javax.*)

is available here:

wlpdevapiibmio.openliberty.transaction_1.1.60.jar  (jakarta.*)

But I can’t seem to find the proper API for the io.openliberty.transaction package. Does anyone know how to access the TransactionManagerFactory? Any help is appreciated.

— UPDATE: Until the API package is available I chose to create the TransactionManager via reflection:

package de.xxx.xxx;

import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.transaction.TransactionManager;
import java.lang.reflect.InvocationTargetException;

@RequestScoped
public class TransactionManagerProducer {

@Produces
public TransactionManager produce() {
try {
  return (TransactionManager)
      Class.forName("com.ibm.tx.jta.TransactionManagerFactory")
          .getDeclaredMethod("getTransactionManager")
          .invoke(null);
} catch (ClassNotFoundException
    | NoSuchMethodException
    | InvocationTargetException
    | IllegalAccessException e) {
  throw new IllegalStateException("TransactionManager could not be created");
}

} }

Advertisement

Answer

For 22.0.0.3, the api is published finally correctly here: https://repo.maven.apache.org/maven2/io/openliberty/api/io.openliberty.transaction/1.1.62/

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement