Atomikos Forum

spring j2ee application needs two phase commit

I am working on spring MVC based j2ee application with jdbc template for back end operations.
I need two commit online database and offline database simultaneously, and if any error occurred both should be rolled back. DB is mysql.

I have developed a code snippet as below
public void insertBank() throws Exception {
    
        System.out.println(" in insert bank");
    
        String insertbank =     "INSERT INTO m_banks (BANK_CD,LANG_CD,BANK_NAME,RECORD_STATUS,ORIGINAL_RECORD)  SELECT(SELECT MAX(BANK_CD)+1 FROM m_banks), 99,'Rajeevs Bank','C',1;";
        String insertbank1 =     "INSERT INTO m_banks (BANK_CD,LANG_CD,BANK_NAME,RECORD_STATUS,ORIGINAL_RECORD)  SELECT(SELECT MAX(BANK_CD)+1 FROM m_banks), 99,'Rajeevs Bank','C',1;";
        
        UserTransactionManager tm = atomikosTransactionManager;
        boolean rollback = false;
        try{
              tm.begin();
                           
               
          offjdbcTemplate.update(insertbank1);        
            
            
      jdbcTemplate.update(insertbank);
            
        }catch (Exception e){
            e.printStackTrace();
            rollback = true;    
            throw e;
        }
        finally {            
            if ( rollback ) {
                atomikosTransactionManager.rollback();
                System.out.println(rollback+" in rollback");
            }
            else{
                atomikosTransactionManager.commit();
                System.out.println(rollback+" in commit");
            }
        }
            
    }



my xml entires as below
  <bean id="atomikosTransactionManager"
        class="com.atomikos.icatch.jta.UserTransactionManager"
        init-method="init" destroy-method="close">    
        <property name="forceShutdown" value="false" />
        <!-- <property name="autocommit" value="true" /> -->
      </bean>
 

 <bean id="offdataSource"
          class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
              <property name="uniqueResourceName"><value>DataSourceB</value></property>
            <property name="xaDataSourceClassName"><value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value></property>
            <property name="xaProperties">
            <props>               
                  <prop key="url"> jdbc:mysql://localhost:3306/db_2014</prop>
                  <prop key="user">root</prop>
                  <prop key="password">cctns</prop>    
                  <prop key="port">3306</prop>
                  <prop key="databaseName">db_2014</prop>
                  <prop key="serverName">localhost</prop>             
              </props>
            </property>       
    </bean>

Data source and jdbc template are injected.  But in the docs it is mentioned, in j2ee applicatin j2eetrnsactionmanager should be used instead of this usertransaction manager. Is this implementation is wrong? how we this j2eetransactionmanager can be implemented ?i have tried , but getting error like , transaction can not be started............pls help me to conitnue.
RajeevP Send private email
Thursday, August 28, 2014
 
 
The J2eeUserTransaction has been replaced by out-of-the-box Tomcat integration as part of our commercial subscription... See http://www.atomikos.com/Main/BuyOnline

Best
Guy Pardon Send private email
Thursday, September 04, 2014
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics