Atomikos Forum |
|
I tried to use atomikos with spring jta transaction mangaer support. Here is my configuration of application-context.xml:
I am making two different datasource beans using atomikos and then injecting them into my database access layer. I am using simpleJdbcTemplate provided by spring to access database.I am doing two consecutive inserts into two different db's using the two datasource beans,and generating a primary key constraint violation in the second database , but my transaction is not rolling back, i mean the data is getting inserted in the first database. I am using annotations for providing transactional support to my methods.Please help me out of this problem, otherwise i will have to do programmatic transaction management using the transaction essentials api.But that will require a lot of code rework because there i will be making a lot of getconnections statements for different datasources. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.0.xsd"> <bean id="rspHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/rsp*">t1Service</prop> </props> </property> </bean> <bean id="dataSource1" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <property name="uniqueResourceName" value="dataSource1" /> <property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" /> <property name="xaProperties"> <props> <prop key="user">root</prop> <prop key="password">root</prop> <prop key="url">jdbc:mysql://172.19.1.80:3306/rsp</prop> <prop key="pinGlobalTxToPhysicalConnection">true</prop> </props> </property> </bean> <bean id="dataSource2" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <property name="uniqueResourceName" value="dataSource2" /> <property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" /> <property name="xaProperties"> <props> <prop key="user">root</prop> <prop key="password">root</prop> <prop key="url">jdbc:mysql://172.19.10.33:3306/rsp</prop> <prop key="pinGlobalTxToPhysicalConnection">true</prop> </props> </property> </bean> <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown" value="true" /> </bean> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> <property name="transactionTimeout"> <value>300</value> </property> </bean> <bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager"> <ref bean="atomikosTransactionManager" /> </property> <property name="userTransaction"> <ref bean="atomikosUserTransaction" /> </property> </bean> <bean id="t1Dao" class= "com.comviva.controller.T1DaoImpl"> <property name="dataSource1"> <ref local="dataSource1" /> </property> <property name="dataSource2"> <ref local="dataSource2" /> </property> </bean> <!-- <bean id="t2Dao" class= "com.comviva.controller.T2DaoImpl"> <property name="dataSource"> <ref bean="dataSource2" /> </property> </bean> --> <bean id="tService" class= "com.comviva.controller.T1ServiceImpl"> <property name="t1Dao"> <ref bean="t1Dao" /> </property> <!-- <property name="t2Dao"> <ref bean="t2Dao" /> </property> --> </bean> <bean id="rspControllerTarget" class="com.comviva.controller.RspController"> <property name="t1Service"> <ref bean="tService" /> </property> </bean> <bean id="t1Service" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="springTransactionManager" /> </property> <property name="target"> <ref bean="rspControllerTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> </beans> |