4

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]

Community
  • 1
  • 1
Chris Owens
  • 1,107
  • 1
  • 10
  • 15
  • What is the class name of the transaction manager that JTA provides by default? I notice that the TomEE+ distribution includes geronimo-transaction and openejb-core, both of which have a fair bit of transaction plumbing in them. – Chris Owens Jul 04 '13 at 15:30

1 Answers1

3

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?

Jukka
  • 4,583
  • 18
  • 14
  • Jukka, thank you, yes, I tried java:comp/env/TransactionManager. I had looked at the documentation page you referenced, but it talks about declaring datasources and the transaction manager in tomee.xml, which as I understand it configures the entire server instance for all applications; I just want to configure the datasoure and transaction manager for a single application. (edited question to clarify this) – Chris Owens Jul 04 '13 at 15:16
  • Spring won't create the underlying container-managed transaction manager or datasources for you, so you need to declare them in tomee.xml (or some other container-specific config file). I do not know if TomEE allows you to limit their scope to a single app though. – Jukka Jul 04 '13 at 16:41
  • But if you REALLY need to, you might be able to declare the TomEE transaction manager and datasources as beans in your spring config. But personally I would just have the container manage them and not worry about the details. – Jukka Jul 04 '13 at 16:44
  • Jukka, "Just have the container manage them and not worry about the details" is exactly what I am trying to accomplish. Could you help me do it? – Chris Owens Jul 07 '13 at 17:25
  • 3
    It turned out to be easier than expected: ` ` – Chris Owens Jul 25 '13 at 04:30