Recently I migrated two, related, JPA + Spring web applications from Tomcat to JBoss 4 and along the way, added support for JMS messaging. Here is what I needed to do to make transactions work in JBoss:
- Persistence.xml -> Changed transaction-type from RESOURCE_LOCAL to JTA.
- Persistence.xml -> Added transaction manager lookup class (see below).
- Persistence.xml -> hibernate.transaction.manager_lookup_class = org.hibernate.transaction.JBossTransactionManagerLookup
- Instead of using jpaTransactionManager, use jtaTransactionManager as below.
<!– For use in Tomcat –>
<!–
<bean id=”jpaTransactionManager” class=”org.springframework.orm.jpa.JpaTransactionManager“>
<property name=”entityManagerFactory” ref=”entityManagerFactory” />
<property name=”dataSource”><ref local=”dataSource”/></property>
<property name=”defaultTimeout” value=”30″></property>
<property name=”nestedTransactionAllowed” value=”true”></property>
</bean>
–>
<!–<tx:annotation-driven transaction-manager=”jpaTransactionManager” />–>
<!– For use in a container only. –>
<bean id=”jtaTransactionManager” class=”org.springframework.transaction.jta.JtaTransactionManager“>
<property name=”userTransactionName” value=”UserTransaction”/>
<property name=”transactionManagerName” value=”java:/TransactionManager”/>
<property name=”jndiTemplate”><ref bean=”jndiTemplate” /></property>
<property name=”autodetectTransactionManager” value=”true”></property>
<property name=”globalRollbackOnParticipationFailure” value=”true”></property>
</bean>
<tx:annotation-driven transaction-manager=”jtaTransactionManager” />
I was in-part helped by this post and the error message: “The chosen transaction strategy requires access to the JTA TransactionManager…”. It appears as if you need a XA data source for this to work correctly,which lead me to discover Bitronix, however my application seems to work with c3p0 combo data source as defined below:
<!– C3P0 Data Source –>
<bean id=”c3p0DataSource” class=”com.mchange.v2.c3p0.ComboPooledDataSource” destroy-method=”close”>
<property name=”driverClass” value=”${etms.dataSource.driverClassName}” />
<property name=”jdbcUrl” value=”${etms.dataSource.url}” />
<property name=”user” value=”${etms.dataSource.username}” />
<property name=”password” value=”${etms.dataSource.password}” />
<property name=”properties” ref=”c3p0ConfigProperties”/>
</bean>
Needless to say, it is straightforward once you do it but until then you have to jump through hoops (Google…) to find clues.