9 Replies Latest reply on Dec 1, 2006 1:05 PM by weston.price

    enlist of resource failed with Oracle

    vassilidzuba

      Hi,

      i'm trying to use JTA with JDBC in a standalone application.
      JTA version is 4.2.2GA
      Oracle JDBC driver is thin 10g R2

      i'm following the example in chapter 6 of the JTA programmer's guide


      TransactionalDriver arjunaJdbcDriver = new TransactionalDriver();
      
      Properties dbProps1 = new Properties();
      dbProps1.setProperty(TransactionalDriver.userName, "...");
      dbProps1.setProperty(TransactionalDriver.password, "...");
      dbProps1.setProperty(TransactionalDriver.dynamicClass, "com.arjuna.ats.internal.jdbc.drivers.oracle_8_1_6");
      
      Connection conn = arjunaJdbcDriver.connect("jdbc:arjuna:jdbc:oracle:thin:@xxxx:1521:yyyy", dbProps1);
      
      ...
      
      com.arjuna.ats.jta.UserTransaction.userTransaction().begin();
      
      ...
      


      When I try to access two different databases with two connections, everything works as expected.

      However, when I try to access the same database with two different connections (using two different users/passwords), i get an exception :

       at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:938)
       at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:244)
       at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.enlistResource(TransactionImple.java:743)
       at com.arjuna.ats.internal.jdbc.ConnectionImple.registerDatabase(ConnectionImple.java:707)
       at com.arjuna.ats.internal.jdbc.ConnectionImple.prepareStatement(ConnectionImple.java:179)
      
      


      Is it a bug, or must I do something special while having two connections to the same base in the same transaction ?

      Thanks in advance for any idea.

      Vassili

        • 1. Re: enlist of resource failed with Oracle
          marklittle

          As you'll see on page 29 of the JTA Programmers Guide, we no longer recommend the dyanmicClass way of accessing JDBC drivers outside of the application server. You should be using JNDI.

          • 2. Re: enlist of resource failed with Oracle
            vassilidzuba

            OK, i'll try that.

            BTW, by putting the user/password in the URL, it works :

            Connection conn = arjunaJdbcDriver.connect("jdbc:arjuna:jdbc:oracle:thin:foo/bar@xxxx:521:yyyy", dbProps1);
            


            • 3. Re: enlist of resource failed with Oracle
              vassilidzuba

              I recoded the program to use JNDI with a JNP provider
              and it works.

              Thanks for the tip.

              Vassili

              • 4. Re: enlist of resource failed with Oracle
                marklittle

                Glad to know. The other way is pretty much deprecated and only guaranteed to work with much older drivers.

                • 5. Re: enlist of resource failed with Oracle
                  vassilidzuba

                  well, i was too optimistic...

                  i had left the user/password in the URL when building the datasource.
                  When i remove them or do not specify explicitely the url, the program
                  fails the same way as before.

                  as far as i understand it, the problem lies in
                  function TxInfo.isNewRM. The call to x.isSameRM(xaRes)
                  at line 1453 returns true while it probably should return false.

                  x and xaRes are instances of T4CXAResource, which is a class private to the Oracle JDBC driver

                  it seems that the function compares the URL, while ignoring the user name.

                  • 6. Re: enlist of resource failed with Oracle
                    marklittle

                    Whatever the isSameRM does is up to the implementation to decide. The TM has to rely upon it returning the correct value. If you think the isSameRM is wrong, then it may be worth checking the Oracle bug system.

                    • 7. Re: enlist of resource failed with Oracle
                      marklittle

                       

                      "vassilidzuba" wrote:
                      well, i was too optimistic...

                      i had left the user/password in the URL when building the datasource.
                      When i remove them or do not specify explicitely the url, the program
                      fails the same way as before.


                      What is the failure message this time? Fairly obviously you will need to provide a username/password valid for the DB you are trying to connect to.

                      • 8. Re: enlist of resource failed with Oracle
                        jhalliday

                        isSameRM in Oracle drivers is basically 'return conn1.getURL() == conn2.getURL()'

                        Hence where the username/pass are part of the URL you get different behavior to the situation where they are properties. I suspect weird things will also happen if you have the hostname in one URL but an equiv IP address in the other. How we should handle this Oracle oddity is a subject for debate. By and large we can't go around second guessing a database's own drivers. For now, just put the username at least into the URL.

                        Jonathan.

                        • 9. Re: enlist of resource failed with Oracle
                          weston.price

                          We actually have to workaround this issue in JBossAS both for Oracle and WebSphereMQ. There is an override flag to accomodate this.