Atomikos Forum |
|
Hi,
I am trying to integrate AbstractRoutingDataSource with atomikos JTA. In the case of multiple inserts, if anyone throws Exception, then in logs it showing STATUS_ROLLEDBACK. But in DB entry is still there. Below are my configurations DAO.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <tx:annotation-driven transaction-manager="transactionManager" /> <tx:jta-transaction-manager /> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"> <property name="defaultPersistenceUnitName" value="idea-jpa" /> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="idea-jpa" /> <property name="dataSource" ref="s-dataSource" /> <property name="jpaDialect"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /> </property> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="showSql" value="false" /> <property name="generateDdl" value="false" /> <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" /> </bean> </property> </bean> <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown" value="false" /> </bean> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction"> <property name="transactionTimeout" value="300" /> </bean> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" depends-on="atomikosTransactionManager,atomikosUserTransaction"> <property name="transactionManager" ref="atomikosTransactionManager" /> <property name="userTransaction" ref="atomikosUserTransaction" /> </bean> <!-- DATA SOURCES DEFINITION --> <bean id="s-dataSource" class="com.mypackage.idea.helper.RoutingDataSource"> <property name="targetDataSources"> <map> <entry key="shard0" value-ref="shard1-dataSource" /> <entry key="shard1" value-ref="shard2-dataSource" /> <entry key="shard2" value-ref="shard3-dataSource" /> <entry key="shard3" value-ref="shard4-dataSource" /> </map> </property> <property name="defaultTargetDataSource" ref="shard1-dataSource" /> </bean> <bean id="shard1-dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <!-- set an arbitrary but unique name for the datasource --> <property name="uniqueResourceName"> <value>XADBMS1</value> </property> <property name="xaDataSourceClassName"> <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value> </property> <property name="xaProperties"> <props> <prop key="user">root</prop> <prop key="password"></prop> <prop key="URL">jdbc:mysql://localhost:3306/idea_1?pinGlobalTxToPhysicalConnection=true </prop> </props> </property> <property name="poolSize" value="30" /> </bean> <bean id="shard2-dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <!-- set an arbitrary but unique name for the datasource --> <property name="uniqueResourceName"> <value>XADBMS2</value> </property> <property name="xaDataSourceClassName"> <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value> </property> <property name="xaProperties"> <props> <prop key="user">root</prop> <prop key="password"></prop> <prop key="URL">jdbc:mysql://localhost:3306/idea_2?pinGlobalTxToPhysicalConnection=true </prop> </props> </property> <property name="poolSize" value="30" /> </bean> <bean id="shard3-dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <!-- set an arbitrary but unique name for the datasource --> <property name="uniqueResourceName"> <value>XADBMS3</value> </property> <property name="xaDataSourceClassName"> <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value> </property> <property name="xaProperties"> <props> <prop key="user">root</prop> <prop key="password"></prop> <prop key="URL">jdbc:mysql://localhost:3306/idea_3?pinGlobalTxToPhysicalConnection=true </prop> </props> </property> <property name="poolSize" value="30" /> </bean> <bean id="shard4-dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <!-- set an arbitrary but unique name for the datasource --> <property name="uniqueResourceName"> <value>XADBMS4</value> </property> <property name="xaDataSourceClassName"> <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value> </property> <property name="xaProperties"> <props> <prop key="user">root</prop> <prop key="password"></prop> <prop key="URL">jdbc:mysql://localhost:3306/idea_4?pinGlobalTxToPhysicalConnection=true </prop> </props> </property> <property name="poolSize" value="30" /> </bean> </beans> *************************************************** persistence.xml <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="idea-jpa" transaction-type="JTA"> <properties> <property name="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup" /> <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory" /> <property name="hibernate.connection.autocommit" value = "false" /> </properties> </persistence-unit> </persistence> ********************************************************* Is anything wrong with above configurations?
Below is pseudo code of how I am trying to insert using @Transactional
Class A() { @Transactional func multipleInserts() { B.insert1(); //--> on shard0 C.insert2(); //--> on shard1 D.insert3(); //--> on shard2 } } Class B() { @Transactional func insert1() { // Business logic } } Class C() { @Transactional func insert2(){ // Business logic } } Class D() { @Transactional func insert3(){ // Business logic } } *********************************** Let's say if the last insert fails, then it should roll back for first two inserts as well. But this is not happening in my case :/
did you get any solution for this. I am having the same problem.
see below default82df.html?community.6.3587.0 Thanks |