Announcement Announcement Module
Collapse
No announcement yet.
JOTM + JTATransactionManager Not Rolling Back Txn? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JOTM + JTATransactionManager Not Rolling Back Txn?

    Hello,

    I'm trying to port over to use JtaTransactionManager as we introduce multiple databases. Using a single DB and DatasourceTransactionManager works great. I was hoping to drop in JtaTransactionManager, but no luck. Even when a RuntimeException is thrown, the txn is not rolled back.

    I'm hoping someone can see a problem in my configuration?

    Thanks!

    Code:
      <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
    
     <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
       <property name="userTransaction"><ref local="jotm"/></property>
     </bean>
    
      <bean id="oracleDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource"
            destroy-method="shutdown">
       <property name="transactionManager"><ref local="jotm"/></property>
       <property name="driverName"><value>oracle.jdbc.OracleDriver</value></property>
       <property name="url"><value>jdbc&#58;oracle&#58;thin&#58;@alewa.ehawaii.gov&#58;1528&#58;hict</value></property>
       <property name="user"><value>seth</value></property>
       <property name="password"><value>seth</value></property>
     </bean>
    
      <bean id="oracleDao" class="test.jdbc.TestDaoImpl">
            <property name="dataSource"><ref local="oracleDataSource" /></property>
      </bean>
    
        <bean id="service" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager"><ref bean="transactionManager"/></property>
            <property name="target">
                <bean class="test.jdbc.ServiceImpl">
                    <property name="mysqlDao"><ref local="mysqlDao" /></property>
                    <property name="oracleDao"><ref local="oracleDao" /></property>
                </bean>
            </property>
            <property name="transactionAttributes">
                <props>
                    <prop key="*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>
    My testing Service is merely:

    Code:
        public void performActionThatWillFail&#40;&#41; &#123;
            oracleDao.insert&#40;"foo"&#41;;
            throw new RuntimeException&#40;"MAKE THIS FAIL AND ROLLBACK"&#41;;
        &#125;
    When I replace my TransactionProxyFactoryBean's transacationManager w/ the DataSourceTransactionManager, it works great (I've also replaced the XADataSource with a StandardDataSource). I drop in JOTM and JTA and it starts to fail.

    Any tips or tricks?

    Thanks very much!

  • #2
    Forgot to mention:

    JDK 1.4.2
    Spring 1.2-dev
    JOTM 2.0.5
    Oracle Driver 10.1.0.20 (jdk1.4)

    Comment


    • #3
      Interesting... it appears that I must use the StandardXAPoolDataSource, and not the StandardXADataSource stand alone. Once I switched to the Pooled data source, things began to work. Even a dist. txn between Oracle and MySQL works now (which, I have to say, is pretty cool).

      Here's the config now:

      Code:
       <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
         <property name="userTransaction"><ref local="jotm"/></property>
       </bean>
       
       <bean id="dataSourceTransactionManager" 
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
          <property name="dataSource"><ref local="oracleDataSource"/></property>
      </bean>
      
       <bean id="innerMysqlDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource"
              destroy-method="shutdown">
         <property name="transactionManager"><ref local="jotm"/></property>
         <property name="driverName"><value>com.mysql.jdbc.Driver</value></property>
         <property name="url"><value>jdbc&#58;mysql&#58;//XXXX/seth</value></property>
       </bean>
       
        <bean id="innerOracleDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource"
              destroy-method="shutdown">
         <property name="transactionManager"><ref local="jotm"/></property>
         <property name="driverName"><value>oracle.jdbc.OracleDriver</value></property>
         <property name="url"><value>jdbc&#58;oracle&#58;thin&#58;@XXXX&#58;1528&#58;hict</value></property>
       </bean>
       
        <bean id="oracleDataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
         <property name="dataSource"><ref local="innerOracleDataSource"/></property>
         <property name="maxSize"><value>5</value></property>
         <property name="minSize"><value>2</value></property>
         <property name="user"><value>seth</value></property>
         <property name="password"><value>XXXX</value></property>
        </bean>
        
          <bean id="mysqlDataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
         <property name="dataSource"><ref local="innerMysqlDataSource"/></property>
         <property name="maxSize"><value>5</value></property>
         <property name="minSize"><value>2</value></property>
         <property name="user"><value>seth</value></property>
         <property name="password"><value>XXXX</value></property>
        </bean>
          
          <bean id="mysqlDao" class="test.jdbc.TestDaoImpl">
              <property name="dataSource"><ref local="mysqlDataSource" /></property>
          </bean>
          
          <bean id="oracleDao" class="test.jdbc.TestDaoImpl">
              <property name="dataSource"><ref local="oracleDataSource" /></property>
          </bean>
          
          <bean id="service" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
              <property name="transactionManager"><ref bean="transactionManager"/></property>
              <property name="target">
                  <bean class="test.jdbc.ServiceImpl">
                      <property name="mysqlDao"><ref local="mysqlDao" /></property>
                      <property name="oracleDao"><ref local="oracleDao" /></property>
                  </bean>
              </property>
              <property name="transactionAttributes">
                  <props>
                      <prop key="*">PROPAGATION_REQUIRED</prop>
                  </props>
              </property>
          </bean>
      Next up: including JMS and JDBC in a dist. txn.

      Comment

      Working...
      X