1 2 3 Previous Next 31 Replies Latest reply on Feb 1, 2007 12:25 PM by weston.price Go to original post
      • 15. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
        weston.price

        I wrote a test case as well. I will post later.

        • 16. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
          weston.price

          Just to make sure...you are using the full version of DB2 right, not DB2-C?

          • 17. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
            apill

            We are using DB2 Express C

            • 18. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
              apill

              As requested I wrote a test that consisted of the following code...

              Injected session:

              @PersistenceContext(unitName="PicsEM")
              Session session;
              


              Method content:
              try
              {
               Statement s = this.session.connection().createStatement();
               String del = "DELETE FROM ZCOREINV.COUNTRY WHERE ZCOREINV.COUNTRY.ID = '158';";
               s.execute(del);
               this.session.close();
              }
              catch (HibernateException e)
              {
               e.printStackTrace();
              }
              catch (SQLException e)
              {
               e.printStackTrace();
              }
              



              The test failed in exactly the same way as before.

              • 19. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
                apill

                What is your concern with me using DB2 Express C 9.1?

                As far as I can tell XA is not disabled in this version.

                http://www-306.ibm.com/software/data/db2/express/getstarted.html


                DB2 Express-C technical info

                Restrictions:

                * Maximum processors: 2
                * Maximum addressable memory: 4GB
                * Database Partitioning Feature N/A
                * Connection Concentrator N/A
                * DB2 Geodetic Extender N/A
                * Query Patroller N/A
                * Net Search Extender N/A

                Operating Systems

                * Linux
                * Windows

                DB2 Express extended features not included in DB2 Express-C:

                * Spatial Extender Client and Samples
                * Microsoft Cluster Server support
                * Informix Data Source Support,
                * Replication Data Capture (both SQL Replication and Replication with MQ Server)
                * DB2 Web tools
                * GSKit
                * APPC and Netbios

                In addition to these extended features which are available in DB2 Express Edition but are not available in DB2 Express-C, there are also a number of add-on features that can be purchased to add functionality to DB2 Express Edition. These add-on features include:

                * Workload Management
                * Performance Optimization
                * High Availability

                These add-on features can not be added to DB2 Express-C. If you would like to use any of these add-on features, you must first purchase a license for DB2 Express Edition, and then purchase the desired add-on features.

                pureXML?

                * In general, DB2 Express-C is a subset of DB2 Express Edition. pureXML is the only exception to this. pureXML is available as an add-on feature to DB2 Express Edition, however it is available for use with DB2 Express-C, and the use of pureXML is included in the base DB2 Express-C license.
                * Check this link for more information about pureXML.


                • 20. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE

                  This error message is an IBM raised error message
                  so you'll need to ask them what the problem is.

                  It's basically refusing to be enlisted in the transaction
                  with the only information being XAER_OUTSIDE.

                  Judging by this link which comes out top on google:
                  http://www-1.ibm.com/support/docview.wss?uid=swg21175904

                  This looks like the same problem as Oracle for which we added
                  where you can't use a connection in a JTA transaction after you used
                  in a local transaction.

                  <no-tx-seperate-pools/>
                  



                  • 21. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
                    weston.price

                    Strange as this would be a recent issue. 9.0.1 works fine but only with Type2. I have yet to verify against a Type4, 9.1 installation yet.

                    • 22. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
                      apill

                      I tried

                      <no-tx-seperate-pools/>


                      with no luck.

                      Is there any way we can get the Type 4 verified with 9.1?

                      How could the connection be used in a local transaction when the data source is setup as XA?

                      Don't know if this is helpful for debugging the cause?
                      http://www-1.ibm.com/support/docview.wss?uid=swg21175904

                      • 23. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
                        apill

                        From the IBM link in my previous post it says in the solution section...


                        If the XAER_OUTSIDE occurs with a method like DB2XAResource.start(), change the application attributes or application to complete the connection.


                        The stack trace of the error in JBoss

                        at com.ibm.db2.jcc.b.bc.a(bc.java:1651)
                        at com.ibm.db2.jcc.b.bc.start(bc.java:1530)
                         at org.jboss.resource.adapter.jdbc.xa.XAManagedConnection.start(XAManagedConnection.java:117)
                         at org.jboss.tm.TransactionImpl$Resource.startResource(TransactionImpl.java:2063)
                        
                        at org.jboss.tm.TransactionImpl.enlistResource(TransactionImpl.java:581)
                        at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TransactionSynchronization.enlist(TxConnectionManager.java:757)
                        at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.enlist(TxConnectionManager.java:548)
                        at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:323)
                        at org.jboss.resource.connectionmanager.BaseConnectionManager2.reconnectManagedConnection(BaseConnectionManager2.java:501)
                        at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:382)
                        at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:812)
                        at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
                        at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:69)
                        


                        • 24. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
                          apill

                          What does it mean by


                          change the application attributes or application to complete the connection.


                          Is that something I can do, or is it something JBoss needs to do?

                          Thanks

                          • 25. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE

                             

                            "apill" wrote:

                            How could the connection be used in a local transaction when the data source is setup as XA?


                            e.g. Hibernate or the EJB2.1 container will check the tables exist during deployment.
                            During deployment there is no JTA transaction, so they are free to do:

                            connection.setAutoCommit(false);
                            try
                            {
                             // check/create tables
                            }
                            finally
                            {
                             connection.commit();
                            
                            }
                            


                            Which is a local transaction.

                            This is option (1) on the list of solutions on the link posted.

                            If this was the problem then using no-tx-seperate-pools would fix it.
                            The connection used outside a JTA transaction would NOT be used
                            for a connection inside a JTA transaction (they would come from different
                            sub-pools).


                            What does it mean by

                            Quote:

                            change the application attributes or application to complete the connection.


                            Is that something I can do, or is it something JBoss needs to do?


                            This is option (2) on the list of solutions.
                            It means you are passing the wrong parameters. This is not the case
                            for JBoss, which will pass the XID and the correct flags to the
                            XAResource.start()

                            Which leaves option (3) - apply patches to fix the database/jdbc driver.

                            ALL THE OTHER QUESTIONS ARE FOR IBM.
                            There is nothing we can do to fix/debug IBM drivers or "guess"
                            what the problem is for an IBM generated error message.
                            (That is short of reverse engineering, which I'm sure is disallowed
                            by their license :-)

                            • 26. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE

                              The first thing you need to do is make sure the XADataSource works outside JBoss.

                              Use IBM to help you on this.

                              Here is the code to test it is working:

                              package test;
                              
                              import java.io.Serializable;
                              import java.util.Arrays;
                              import java.util.Random;
                              
                              import javax.sql.XAConnection;
                              import javax.transaction.xa.XAResource;
                              import javax.transaction.xa.Xid;
                              
                              import com.ibm.db2.jcc.DB2XADataSource;
                              
                              public class Test
                              {
                               public static void main(String[] args) throws Exception
                               {
                               DB2XADataSource xaDataSource = new DB2XADataSource();
                               xaDataSource.setDataBase("zcoreinv");
                               xaDataSource.setUser("zcoreinv");
                               xaDataSource.setPassword("zcoreinv");
                               xaDataSource.setPortNumber(500);
                               xaDataSource.setServerName("localhost");
                               xaDataSource.setDriverType(4);
                              
                               XAConnection xaConnection = xaDataSource.getXAConnection();
                               XAResource xaResource = xaConnection.getXAResource();
                               XidImpl xid = new XidImpl();
                               xaResource.start(xid, XAResource.TMNOFLAGS);
                               }
                              
                               public static class XidImpl implements Serializable, Xid
                               {
                               private static final long serialVersionUID = -2227021688745286343L;
                              
                               private static Random random = new Random();
                              
                               private int formatId = 876;
                              
                               private byte[] globalTransactionId;
                              
                               private byte[] branchQualifier = new byte[0];
                              
                               private transient String cachedToString;
                              
                               private transient int cachedHashCode;
                              
                               public XidImpl()
                               {
                               globalTransactionId = new byte[10];
                               random.nextBytes(globalTransactionId);
                               }
                              
                               public int getFormatId()
                               {
                               return formatId;
                               }
                              
                               public byte[] getGlobalTransactionId()
                               {
                               return globalTransactionId;
                               }
                              
                               public byte[] getBranchQualifier()
                               {
                               return branchQualifier;
                               }
                              
                               public boolean equals(Object object)
                               {
                               if (object == this)
                               return true;
                               if (object == null || object instanceof Xid == false)
                               return false;
                              
                               Xid other = (Xid) object;
                               return
                               (
                               formatId == other.getFormatId() &&
                               Arrays.equals(globalTransactionId, other.getGlobalTransactionId()) &&
                               Arrays.equals(branchQualifier, other.getBranchQualifier())
                               );
                               }
                              
                               public int hashCode()
                               {
                               if (cachedHashCode == 0)
                               {
                               cachedHashCode = formatId;
                               for (int j = 0; j < globalTransactionId.length; ++j)
                               cachedHashCode += globalTransactionId[ j ];
                               }
                               return cachedHashCode;
                               }
                              
                               public String toString()
                               {
                               if (cachedToString == null)
                               {
                               StringBuffer buffer = new StringBuffer();
                               buffer.append("XidImpl[FormatId=").append(getFormatId());
                               buffer.append(" GlobalId=").append(new String(getGlobalTransactionId()).trim());
                               byte[] branchQualifer = getBranchQualifier();
                               buffer.append(" BranchQual=");
                               if (branchQualifer == null)
                               buffer.append("null");
                               else
                               buffer.append(new String(getBranchQualifier()).trim());
                               buffer.append(']');
                               cachedToString = buffer.toString();
                               }
                               return cachedToString;
                               }
                               }
                              }
                              


                              • 27. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
                                apill

                                Thanks. I'll give that a go.

                                • 28. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE
                                  apill

                                  I ran the following code and it successfully updated the database within an XA transaction. I also tested rolling back the tx and this worked successfully.

                                  Is there anything else you would like me to test?

                                  package test;
                                  
                                  import java.io.Serializable;
                                  import java.sql.Connection;
                                  import java.sql.Statement;
                                  import java.util.Arrays;
                                  import java.util.Random;
                                  
                                  import javax.sql.XAConnection;
                                  import javax.transaction.xa.XAException;
                                  import javax.transaction.xa.XAResource;
                                  import javax.transaction.xa.Xid;
                                  
                                  import com.ibm.db2.jcc.DB2XADataSource;
                                  
                                  public class Test
                                  {
                                   public static void main(String[] args) throws Exception
                                   {
                                  
                                   DB2XADataSource xaDataSource = new DB2XADataSource();
                                   xaDataSource.setDatabaseName("ZCOREINV");
                                   xaDataSource.setUser("zcoreinv");
                                   xaDataSource.setPassword("zcoreinv");
                                   xaDataSource.setPortNumber(50000);
                                   xaDataSource.setServerName("localhost");
                                   xaDataSource.setDriverType(4);
                                  
                                   XAConnection xaConnection = xaDataSource.getXAConnection();
                                   XAResource xaResource = xaConnection.getXAResource();
                                   XidImpl xid = new XidImpl();
                                  
                                   final Connection connection = xaConnection.getConnection();
                                   final Statement statement = connection.createStatement();
                                  
                                   try
                                   {
                                   xaResource.start(xid, XAResource.TMNOFLAGS);
                                   statement.executeUpdate("DELETE FROM ZCOREINV.COUNTRY WHERE ID = '53'");
                                   xaResource.end(xid, XAResource.TMSUCCESS);
                                  
                                   int ret = xaResource.prepare(xid);
                                  
                                   xaResource.commit(xid, false);
                                   }
                                   catch (XAException e)
                                   {
                                   e.printStackTrace();
                                   }
                                   finally
                                   {
                                   statement.close();
                                   connection.close();
                                   xaConnection.close();
                                   }
                                  
                                   }
                                  
                                   public static class XidImpl implements Serializable, Xid
                                   {
                                   private static final long serialVersionUID = -2227021688745286343L;
                                  
                                   private static Random random = new Random();
                                  
                                   private int formatId = 876;
                                  
                                   private byte[] globalTransactionId;
                                  
                                   private byte[] branchQualifier = new byte[0];
                                  
                                   private transient String cachedToString;
                                  
                                   private transient int cachedHashCode;
                                  
                                   public XidImpl()
                                   {
                                   globalTransactionId = new byte[10];
                                   random.nextBytes(globalTransactionId);
                                   }
                                  
                                   public int getFormatId()
                                   {
                                   return formatId;
                                   }
                                  
                                   public byte[] getGlobalTransactionId()
                                   {
                                   return globalTransactionId;
                                   }
                                  
                                   public byte[] getBranchQualifier()
                                   {
                                   return branchQualifier;
                                   }
                                  
                                   public boolean equals(Object object)
                                   {
                                   if (object == this)
                                   return true;
                                   if (object == null || object instanceof Xid == false)
                                   return false;
                                  
                                   Xid other = (Xid) object;
                                   return
                                   (
                                   formatId == other.getFormatId() &&
                                   Arrays.equals(globalTransactionId, other.getGlobalTransactionId()) &&
                                   Arrays.equals(branchQualifier, other.getBranchQualifier())
                                   );
                                   }
                                  
                                   public int hashCode()
                                   {
                                   if (cachedHashCode == 0)
                                   {
                                   cachedHashCode = formatId;
                                   for (int j = 0; j < globalTransactionId.length; ++j)
                                   cachedHashCode += globalTransactionId[ j ];
                                   }
                                   return cachedHashCode;
                                   }
                                  
                                   public String toString()
                                   {
                                   if (cachedToString == null)
                                   {
                                   StringBuffer buffer = new StringBuffer();
                                   buffer.append("XidImpl[FormatId=").append(getFormatId());
                                   buffer.append(" GlobalId=").append(new String(getGlobalTransactionId()).trim());
                                   byte[] branchQualifer = getBranchQualifier();
                                   buffer.append(" BranchQual=");
                                   if (branchQualifer == null)
                                   buffer.append("null");
                                   else
                                   buffer.append(new String(getBranchQualifier()).trim());
                                   buffer.append(']');
                                   cachedToString = buffer.toString();
                                   }
                                   return cachedToString;
                                   }
                                   }
                                  }
                                  


                                  • 29. Re: EJB3 - XA datasource - Transactions - XAER_OUTSIDE

                                    And do you get XAER_OUTSIDE for the following change?

                                     final Connection connection = xaConnection.getConnection();
                                     connection.setAutoCommit(false);
                                    


                                    What about?
                                     final Connection connection = xaConnection.getConnection();
                                     connection.setAutoCommit(false);
                                     connection.setAutoCommit(true);
                                    


                                    If so, like I said before
                                    <no-tx-seperate-pools/>
                                    will fix it

                                    Except for the fact that you are getting the statement before
                                    enlisting the XAResource, this is exactly the code that JBoss is executing.
                                    Move the XAResource.start() to before the createStatement() to check it exactly,
                                    I doubt it will make a difference?

                                    For anything further, you need to provide logs, see the post at the top of forum.

                                    You still need to ask IBM what the XAER_OUTSIDE means exactly,
                                    you can't expect us to keep guessing test code that might reproduce.
                                    There aren't enough hours in the day. :-)