1 Reply Latest reply on Oct 24, 2006 1:29 AM by Weston M. Price

    UserTransaction not rollsback MySql changes, but Oracle.



      I have the requirement to implement distributed transactions, since i am having three different datasources
      Oracle, MySql. In every transaction i will be updating in both the Oracle and MySql databases.

      So i decided to use the Distributed Transactions (XA) with JTA (i.e., javax.transaction.UserTransaction)
      on the JBoss application server.

      I have configured XA Datasources for Oracle as below (i.e., in oracle-xa-ds.xml )

      i) oracle-xa-ds.xml (This i have placed in D:\jboss-4.0.2\server\default\deploy directory)

      <xa-datasource-property name="URL">jdbc:oracle:thin:@</xa-datasource-property>
      <xa-datasource-property name="User">irmuser</xa-datasource-property>
      <xa-datasource-property name="Password">irmuser</xa-datasource-property>
      <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
      <!-- Checks the Oracle error codes and messages for fatal errors -->
      <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->




      <depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager

      ii) and mysql-xa-ds.xml (also placed at D:\jboss-4.0.2\server\default\deploy directory)

      <xa-datasource-property name="URL">jdbc:mysql://</xa-datasource-property>



      I am not using any EJB stuff, I have simple DAO objects which are plain java class, queries the database using sql Connection, Statment ..etc.
      where i am initiating the UserTransaction.

      Here is my application code

      //getting the UserTransaction with the help of utility called DAOUtil,
      //where jndi lookup is performed for "java:comp/UserTransaction"

      UserTransaction utx = DAOUtil.getUserTransaction();

      //Declare the java.sql.Connection objects
      Connection oraConn = null;
      Connection mysqlConn =null;

      //Begin the UserTransaction

      //Get the oraConn performing jndi lookup for "java:testXAOracleDS"
      oraConn = DAOUtil.getOraConnection();

      //Get the mysqlConn performing jndi lookup for "java:testXAMySqlDS"
      mysqlConn = DAOUtil.getMySqlConnection();

      //Now insert service record into oracle database using the oraConn instance
      //This reads the DTO and inserts the record
      ServiceDAO.addService(serviceDTO, oraConn);

      //Now insert service record into mysql database using the mysqlConn instance
      ServiceDAO.addService(serviceDTO, mysqlConn);

      //Now for testing purpose, Voluntarily throwing the exception as below
      throw new Exception("Throwing exception voluntarily....");

      //commit the UserTransaction
      utx.commit(); //Commit

      }catch(Exception e){
      if (utx != null) {
      try {
      logger.error("Exception occured rolling back the transaction ..."+e.getMessage());
      utx.rollback(); //Rollback
      } catch (SystemException sysex) {

      If you look at the above code, i am throwing the exception voluntarily,
      so it is coming to catch block and utx.rollback() is invoked....

      Here database changes are rolledback from the Oracle database, but not from MySql database.
      Can you please help ?? Did i miss any configuration ?? I am using the JBoss TransactionManager only.

      i.e., jboss-service.xml have the following mbean configuration.

      | The fast in-memory transaction manager.

      <mbean code="org.jboss.tm.TransactionManagerService"
      <!-- set to false to disable transaction demarcation over IIOP -->
      <depends optional-attribute-name="XidFactory">jboss:service=XidFactory

      I ran the following script to make Oracle XA compliant

      But i saw over net that MySql Connector is already supports XA directly (i.e.,mysql-connector-java-5.0.3.jar)

      Appreciate your help in this regard.

      Thanks in advance.