4 Replies Latest reply on Nov 1, 2004 12:49 PM by Adrian Brock

    Using UserTransaction from a Mbean doesn't commit against XA

    Alex Oscar Newbie

      I am not sure if I post this to JMX forum or here, hoping this is the right place. I've defined an Xa Oracle Datasource and I'm using UserTransaction to commit, but it is not happening (I am not getting any error or something) Here's the simplified code below (the actual code involves a distributed transaction, that's why I need to use UserTransaction, If I change the ut.commit() below with the m_db_conn.commit(); it would commit, so please don't suggest that)

      try {
       InitialContext iniCtx = new InitialContext();
       DataSource ds = (DataSource) iniCtx.lookup("java:/OracleDS/XA_TX/MyDB");
       UserTransaction ut = (UserTransaction) iniCtx.lookup("UserTransaction");
       Connection m_db_conn = ds.getConnection();
       m_db_conn.setAutoCommit(false);
       String storedProc = "begin insert into test values (to_char(sysdate,'SSSSS')) ; end;";
       CallableStatement update_stmt = m_db_conn.prepareCall(storedProc);
       ut.begin();
       update_stmt.execute();
       ut.commit();
       System.out.println("{{{Insert DB}}}}");
       } catch (Exception e) { System.out.println("Error testUT "+ e.getMessage()); }


      And here's the -ds.xml file

      <datasources>
       <xa-datasource>
       <jndi-name>OracleDS/XA_TX/MyDB</jndi-name>
       <isSameRM-override-value>false</isSameRM-override-value>
       <xa-datasource-property name="URL">jdbc:oracle:thin:@myacme.com:1521:orcl</xa-datasource-property>
       <track-connection-by-tx>true</track-connection-by-tx>
       <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
       <xa-datasource-property name="User">scott</xa-datasource-property>
       <xa-datasource-property name="Password">tiger</xa-datasource-property>
       <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
       <!-- valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name -->
       <!-- Checks the Oracle error codes and messages for fatal errors -->
       <!-- exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name -->
       <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
       <no-tx-separate-pools/>
       </xa-datasource>
      
      </datasources>