Narayana JTS with Spring in Tomee
shabin8780 Sep 9, 2015 12:19 AMI am trying to use Narayana JTS with Spring in Tomee to make transaction work across multiple instances. I don't want to use EJB and is trying to implement it in the Jacorb IIOP way. I tried to follow the spring integration part of http://narayana.io/docs/specs/server-integration-guide.pdf but even with a single instance and multiple datasource(for two different modules), 2pc doesn't seem to be working. What I am doing is in a single @Transactional method, I am accessing multiple xa-datasources. Success flow is working as expected. But even on exception, the data to the first data source is getting persisted and is not rolled back. This code is working fine if I am using tomee's container transaction manager. Also this is working on wildfly with jts configuration. Only issue is with jts and tomee. So I think it is an issue with my configuration. As this is not working I am not able to proceed to my next step which is to make transaction across multiple tomee instances work. So please advise on the configurations needed for this to work.
These are my current configs:
1. datasource definition
<Resource name="jdbc/NGADataSourceAppln" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" description="Newgen sample application" username="app" password="a" driverClassName="org.apache.derby.jdbc.ClientXADataSource" JtaManaged="true" databaseName="GEMSDB" url="jdbc:derby://localhost:1527/GEMSDB;create=true" /> <Resource name="jdbc/NGADSTechriLlocal" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" description="Newgen sample application for techri local" username="app" password="a" driverClassName="org.apache.derby.jdbc.ClientXADataSource" JtaManaged="true" databaseName="TechRILocalDB" url="jdbc:derby://localhost:1527/TechRILocalDB;create=true" />
2.jndi lookup
<jee:jndi-lookup id="jdbc/NGADataSourceAppln" jndi-name="jdbc/NGADataSourceAppln"/> <jee:jndi-lookup id="jdbc/NGADSTechriLlocal" jndi-name="jdbc/NGADSTechriLlocal"/>
3. transactionManager and entityManagerFactory beans(similar definition is there for the other module with the other datasource)
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager"> <ref bean="jbossTransactionManager"></ref> </property> <property name="userTransaction"> <ref bean="jbossUserTransaction"></ref> </property> <property name="transactionSynchronizationRegistry"> <ref bean="jbossTransactionSyncReg"></ref> </property> </bean> <bean id="jbossTransactionManager" class="com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple"> <property name="transactionTimeout" value="100"/> </bean> <bean id="jbossUserTransaction" class="com.arjuna.ats.internal.jta.transaction.jts.UserTransactionImple"> </bean> <bean id="jbossTransactionSyncReg" class="com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple"> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="jtaDataSource" ref="jdbc/NGADataSourceAppln" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /> </property> <property name="jpaPropertyMap"> <map> <entry key="hibernate.temp.use_jdbc_metadata_defaults" value="false" /> <entry key="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" /> <entry key="hibernate.transaction.manager_lookup_class" value="test.JBossTransactionManagerLookup" /> </map> </property> <property name="packagesToScan"> <list> <value>ngsample.techri.**.*</value> </list> </property> </bean>
4. TransactionManagerLookup
package test; import java.util.Properties; import javax.transaction.Transaction; import javax.transaction.TransactionManager; import org.hibernate.HibernateException; import org.hibernate.transaction.TransactionManagerLookup; import org.springframework.context.annotation.Configuration; @Configuration public class JBossTransactionManagerLookup implements TransactionManagerLookup { private static final TransactionManager TRANSACTION_MANAGER_INSTANCE; static { TRANSACTION_MANAGER_INSTANCE = com.arjuna.ats.jta.TransactionManager.transactionManager(); if (null == TRANSACTION_MANAGER_INSTANCE) { throw new HibernateException("Could not obtain arjuna Transaction Manager instance."); } } public TransactionManager getTransactionManager(Properties props) { return TRANSACTION_MANAGER_INSTANCE; } public String getUserTransactionName() { return null; } public Object getTransactionIdentifier(Transaction transaction) { return transaction; } }
5.Setup code
com.arjuna.orbportability.ORB myORB = com.arjuna.orbportability.ORB.getInstance("ServerSide"); com.arjuna.orbportability.RootOA myOA = com.arjuna.orbportability.OA.getRootOA(myORB); myORB.initORB(new String[] {}, null); try { myOA.initOA(); ORBManager.setORB(myORB); ORBManager.setPOA(myOA); //myOA.run(); } catch (InvalidName e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Also, if you can, please make a jts-spring quickstart.