Search code examples
tomcatjbosseclipselinkjta

How to use Narayana JTA 5.0.3.Final to provide support for XA transactions to web applications running inside Tomcat?


I am trying to use JTA 1.2 outside Java EE compliant Application Server such as in Apache Tomcat, what I've tried so far is following Mr. Jonathan Halliday's way, and How to Configure Server Platform Using Java

But I got following Exception

-javax.faces.FacesException: #{utama.satu}: javax.enterprise.context.ContextNotActiveException: ARJUNA016105: Could not lookup the TransactionManager

-Caused by: javax.faces.el.EvaluationException: javax.enterprise.context.ContextNotActiveException: ARJUNA016105: Could not lookup the TransactionManager

-Caused by: javax.enterprise.context.ContextNotActiveException: ARJUNA016105: Could not lookup the TransactionManager

-Caused by: javax.naming.NameNotFoundException: Name [TransactionManager] is not bound in this Context. Unable to find [TransactionManager].

Here is my META-INF/context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="" reloadable="true">
<Resource auth="Container" factory="org.jboss.weld.resources.ManagerObjectFactory" name="BeanManager" type="javax.enterprise.inject.spi.BeanManager"/>
<Transaction factory="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple"/>
<ResourceLink global="jdbc/coba" name="jdbc/coba" type="javax.sql.DataSource" />
</Context>

and here is my conf/server.xml:

<GlobalNamingResources>
    ....
    <Resource name="jdbc/coba" 
        auth="Container"
        type="javax.sql.DataSource"
        factory="org.jboss.jbossts.tomcat.TransactionalResourceFactory"
        XADataSourceImpl="com.microsoft.sqlserver.jdbc.SQLServerXADataSource"
        xa.setUser="sa"
        xa.setPassword="123456"
        xa.setURL="jdbc:sqlserver://127.0.0.1:1433;databaseName=hrd;"
        />
    ....
</GlobalNamingResources>

this is my persistence.xml, it shows how I reref the datasource:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="sungguhPU" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>java:comp/env/jdbc/coba</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <validation-mode>NONE</validation-mode>
        <properties>
            <property name="eclipselink.session.customizer" value="id.ac.ums.tomcat.JPAEclipseLinkSessionCustomizer"/>
            <property name="eclipselink.logging.level" value="FINEST"/> 
            <property name="eclipselink.id-validation" value="NONE"/>
        </properties>
    </persistence-unit>
</persistence>

I've also built my customer org.eclipse.persistence.config.SessionCustomizer as described by official EclipseLink documentation, but I am still stuck on the same exception for last 24 hours :-(


Solution

  • didn't check in details impl you use but did you provide a TransactionSynchronizationRegistry? That's how @TransactionScoped is implemented

    you need to provide depending your impl java:comp/TransactionManager and/or java:comp/TransactionSynchronizationRegistry