1 Reply Latest reply on Oct 6, 2008 8:30 AM by Vicky Kak

    Transaction error when using multiple xa-datasources

    Denis Cossutta Newbie

      Hi,

      I have a problem using multiple xaresources on jboss-4.2.2. The scenario is the following one:

      I have an EJB3 application which needs to connect to 3 different databases (i.e. 3 different database schemas) and exxecute update operations on the schemas within ine transaction. The database is Oracle 10 and I use JPA to iteract with the db entities (with hibernate 3.2, which is provided with jboss). For example one session bean has to do the following operations:

      1. Insert or Update some tables in the first schema

      2. Insert or Update some tables in the second schema

      3. Insert or update some tables in the third schema



      For each schema connection i declare a datasource file inside the jboss deploy directory:

      scema1-ds.xml
      schema2-ds.xml
      schema3-ds.xml

      I use xa-datasource, so for example the schema1-ds.xml is:

      <?xml version="1.0" encoding="UTF-8"?>

      <xa-datasource>
      <jndi-name>schema1DS</jndi-name>
      <track-connection-by-tx>true</track-connection-by-tx>
      <isSameRM-override-value>false</isSameRM-override-value>
      <xa-datasource-class>
      oracle.jdbc.xa.client.OracleXADataSource
      </xa-datasource-class>
      <xa-datasource-property name="URL">jdbc:oracle:thin:@localhost:1521:oracle10</xa-datasource-property>
      <xa-datasource-property name="User">schema1user</xa-datasource-property>
      <xa-datasource-property name="Password">schema1password</xa-datasource-property>
      <exception-sorter-class-name>
      org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
      </exception-sorter-class-name>
      <no-tx-separate-pools/>

      <type-mapping>Oracle9i</type-mapping>

      </xa-datasource>


      the other schemas have the same file structure.
      Now, when I try to execute the session bean, it performs the operations but when the session bean ends and JBOSS has to end the transaction I have the following exception:

      
      ERROR [org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory] End transaction failed for XAResource
      
      oracle.jdbc.xa.OracleXAException
      
       at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1160)
      
       at oracle.jdbc.xa.client.OracleXAResource.end(OracleXAResource.java:471)
      
       at org.jboss.resource.adapter.jdbc.xa.XAManagedConnection.end(XAManagedConnection.java:147)
      
       at org.jboss.resource.connectionmanager.xa.JcaXAResourceWrapper.end(JcaXAResourceWrapper.java:58)
      
       at com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord.topLevelPrepare(XAResourceRecord.java:259)
      
       at com.arjuna.ats.arjuna.coordinator.BasicAction.doPrepare(BasicAction.java:2871)
      
       at com.arjuna.ats.arjuna.coordinator.BasicAction.doPrepare(BasicAction.java:2828)
      
       at com.arjuna.ats.arjuna.coordinator.BasicAction.prepare(BasicAction.java:2382)
      
       at com.arjuna.ats.arjuna.coordinator.BasicAction.End(BasicAction.java:1783)
      
       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:88)
      
       at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
      
       at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
      
       at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
      
       at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
      
       at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
      
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
      
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:166)
      
       at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:115)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
      
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
      
       at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
      
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
      
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
      
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
      
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
      
      2008-10-03 16:34:58,593 WARN [org.jboss.resource.connectionmanager.TxConnectionManager] Connection error occured: org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener@efd40d[state=NORMAL mc=org.jboss.resource.adapter.jdbc.xa.XAManagedConnection@967a36 handles=0 lastUse=1223044394875 permit=true trackByTx=true mcp=org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool@13180f7 context=org.jboss.resource.connectionmanager.InternalManagedConnectionPool@109fb9e xaResource=org.jboss.resource.connectionmanager.xa.JcaXAResourceWrapper@14acd0b txSync=null]
      oracle.jdbc.xa.OracleXAException
      
       at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1160)
      
       at oracle.jdbc.xa.client.OracleXAResource.end(OracleXAResource.java:471)
      
       at org.jboss.resource.adapter.jdbc.xa.XAManagedConnection.end(XAManagedConnection.java:147)
      
       at org.jboss.resource.connectionmanager.xa.JcaXAResourceWrapper.end(JcaXAResourceWrapper.java:58)
      
       at com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord.topLevelPrepare(XAResourceRecord.java:259)
      
       at com.arjuna.ats.arjuna.coordinator.BasicAction.doPrepare(BasicAction.java:2871)
      
       at com.arjuna.ats.arjuna.coordinator.BasicAction.doPrepare(BasicAction.java:2828)
      
       at com.arjuna.ats.arjuna.coordinator.BasicAction.prepare(BasicAction.java:2382)
      
       at com.arjuna.ats.arjuna.coordinator.BasicAction.End(BasicAction.java:1783)
      
       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:88)
      
       at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
      
       at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
      
       at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
      
       at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
      
       at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
      
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
      
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:166)
      
       at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:115)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
      
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
      
       at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
      
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
      
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
      
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
      
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
      
      2008-10-03 16:34:58,609 WARN [com.arjuna.ats.jta.logging.loggerI18N] [com.arjuna.ats.internal.jta.resources.arjunacore.preparefailed] [com.arjuna.ats.internal.jta.resources.arjunacore.preparefailed] XAResourceRecord.prepare - prepare failed with exception XAException.XAER_RMERR
      2008-10-03 16:34:58,609 WARN [com.arjuna.ats.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_50] - Prepare phase of action -53e1f05f:11db:48e62d0e:49 received heuristic decision: TwoPhaseOutcome.HEURISTIC_HAZARD
      2008-10-03 16:34:58,609 WARN [com.arjuna.ats.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_36] - BasicAction.End() - prepare phase of action-id -53e1f05f:11db:48e62d0e:49 failed.
      2008-10-03 16:34:58,609 WARN [com.arjuna.ats.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_37] - Received heuristic: TwoPhaseOutcome.HEURISTIC_HAZARD .
      2008-10-03 16:34:58,609 WARN [com.arjuna.ats.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_38] - Action Aborting
      2008-10-03 16:34:58,625 ERROR [org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory] End transaction failed for XAResource
      oracle.jdbc.xa.OracleXAException
      


      Instead, if I declare the datasources as local-xa-resources as for example:
      
      <datasources>
       <local-tx-datasource>
       <jndi-name>schema1DS</jndi-name> <connection-url>jdbc:oracle:thin:@localhost:1521:oracle10</connection-url>
       <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
       <user-name>scema1username</user-name>
       <password>schema1password</password> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
       <metadata>
       <type-mapping>Oracle9i</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>
      
      



      everything works, i.e. the transaction is successfully ended (committed), but I have a warning message:

      2008-10-03 09:34:18,937 WARN [com.arjuna.ats.jta.logging.loggerI18N] [com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.multipleWarning] [com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.multipleWarning] Multiple last resources have been added to the current transaction. This is transactionally unsafe and should not be relied upon. Current resource is org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@e9e162

      Is this the proper solution? Do I have to care about this warning? is there I way to avoid it and to use the xa-resources instead of local-xa-resources?