Question

I have an application that uses Spring's declarative transaction management. How can I deploy this in a TomEE+ container so that the application uses TomEE's JTA transaction manager?

More specifically, how can I refer to the built-in transaction manager from within Spring's "application-context.xml" file?

Spring's transaction management configuration seems to want to look up the transaction manager either by a bean reference or by JNDI lookup; I have spent a day researching this and looking at source code; I have found a lot of discussion of the issue (references below) but no definitive how-to.

What I have in the application's META-INF/persistence.xml is this:

<persistence-unit name="myPersistenceUnit" transaction-type="JTA">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <jta-data-source>myDs-managed</jta-data-source>
    <non-jta-data-source>myDs-unmanaged</non-jta-data-source>
    <properties>
        <property name="openjpa.jdbc.DBDictionary" 
            value="org.apache.openjpa.jdbc.sql.PostgresDictionary"/>       
        <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
        <property name="openjpa.Run
        <property name="openjpa.Log" value="slf4j" />
    </properties>
</persistence-unit>

And, in the applications META-INF/spring/applicationContext.xml file I have this: (I have tried various values for transactionManagerName as suggested in various discussions of the topic, as it appears to be non-standard across application servers

<tx:annotation-driven mode="aspectj" transaction-manager="txManager" />
<bean class="org.springframework.transaction.jta.JtaTransactionManager"
        id="txManager">
        <property name="transactionManagerName" 
                       value=" java:comp/TransactionManager"/>
</bean>

Here's an example that is claimed to work for JBoss: Spring JTA configuration - how to set TransactionManager?

Here's a near miss that won't work in an xml configuration file: https://issues.apache.org/jira/browse/TOMEE-38

Here's how to do it within java code if you have your hands on initialContext: http://osdir.com/ml/users.openejb.apache.org/2012-11/msg00110.html

[Edit: The Tomee documentation talks about how to declare a transaction manager, but it says to do it in Tomee.xml, which belongs to the server and not to the individual webapp; I want to configure the transaction manager for a single app and not for the whole server: http://tomee.apache.org/containers-and-resources.html]

Was it helpful?

Solution

Have you tried java:comp/env/TransactionManager for the transactionManagerName? , Also have you declared the TransactionManager and DataSource as described here: http://tomee.apache.org/containers-and-resources.html?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top