2 Replies Latest reply on Oct 18, 2009 9:14 PM by Ketan Maydeo

    Wire XA transactions with Spring 2.5, JBossTS, Hibernate

    Ketan Maydeo Newbie

      Hi,

      I'm working on 2PC for two database resources, Oracle and As400/DB2 using Spring 2.5, JBoss AS 5.1, JBossTS 4.6.1.GA and Hibernate 3.

      As a starting point,I refered to the article on Javaworld
      http://www.javaworld.com/javaworld/jw-04-2007/jw-04-xa.html

      According to JBossTS documentation,
      "There are two ways in which the JBossJTA JDBC support can obtain XADataSources.
      1) DynamicClass instantiation 2) JNDI


      I'm trying to get the TransactionalDriver class to use a JNDI registered XADataSource.

      Let' say that I've JNDI registered XADataSource named "ies".



      com.arjuna.ats.jdbc.TransactionalDriver




      I get the following error.
      18:30:26,679 INFO [STDOUT] IBW 0 [HDScanner] ERROR org.hibernate.util.JDBCExceptionReporter - [com.arjuna.ats.internal.jdbc.jndierror] Could not resolve JNDI XADataSource

      I would appreciate if someone could help me on this issue.

      tHanks.

      Ketan

        • 1. Re: Wire XA transactions with Spring 2.5, JBossTS, Hibernate
          Jonathan Halliday Master

          You'd be better of starting with the JBoss docs, which say the JBossTS transactional driver is only for standalone use, not inside the app server. Use the app server's normal -ds.xml file with <xa-datasource> and trust it to do the right thing.

          • 2. Re: Wire XA transactions with Spring 2.5, JBossTS, Hibernate
            Ketan Maydeo Newbie

            I am supplying a code snippet here to help you understand what I'm doing.

            First, I am just verifying if I can access JNDI datasource. "ds = (XADataSource) ctx2.lookup(dataSourceName); " That piece works fine.

            But then I try to use transactional driver and it doesn't work.
            The problem is that the transactional driver is not finding the datasource. It may have problems with the java namespace or problems with jndi in general.


            javax.sql.XADataSource ods = new OracleXADataSource();

            String sp = "com.sun.jndi.fscontext.RefFSContextFactory";
            String file = "file:/c:/JNDI";
            String dataSourceName = "jdbc/ies";

            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY, sp);
            env.put(Context.PROVIDER_URL, file);
            Context ctx1 = new InitialContext(env);
            ((OracleXADataSource) ods)
            .setURL("jdbc:oracle:thin:@ken-soradev04.ii-corpnet.com:1526:webd1");
            ctx1.rebind(dataSourceName, ods);

            XADataSource ds = null;
            Context ctx2 = new InitialContext(env);
            ds = (XADataSource) ctx2.lookup(dataSourceName);

            XAConnection conn = ds
            .getXAConnection("SOA_DEV1_USER", "SOA_DEV1_USER");

            PreparedStatement stm = conn.getConnection().prepareStatement(
            "select * from contact");
            stm.execute();
            stm.close();

            Properties dbProps = new Properties();
            dbProps.setProperty(TransactionalDriver.userName, "SOA_DEV1_USER");
            dbProps.setProperty(TransactionalDriver.password, "SOA_DEV1_USER");

            String url = "jdbc:arjuna:jdbc/ies";

            TransactionalDriver arjunaJDBC2Driver = new TransactionalDriver();
            try {

            Connection connection = arjunaJDBC2Driver.connect(url, dbProps);
            PreparedStatement statement = connection
            .prepareStatement("select * from contact");
            statement.execute();
            statement.close();

            } catch (SQLException e) {
            e.printStackTrace();
            }

            This is the error I get

            IBW 0 [main] DEBUG com.arjuna.ats.jdbc.logging.logger - TransactionalDriver.TransactionalDriver ()
            IBW 0 [main] DEBUG com.arjuna.ats.jdbc.logging.logger - TransactionalDriver.TransactionalDriver ()
            IBW 0 [main] DEBUG com.arjuna.ats.jdbc.logging.logger - TransactionalDriver.connect ( jdbc:arjuna:jdbc/ies )
            IBW 16 [main] DEBUG com.arjuna.ats.jdbc.logging.logger - ConnectionImple.ConnectionImple ( jdbc/ies )
            IBW 16 [main] DEBUG com.arjuna.ats.jdbc.logging.logger - IndirectRecoverableConnection.IndirectRecoverableConnection ( jdbc/ies, SOA_DEV1_USER, SOA_DEV1_USER )
            java.sql.SQLException: [com.arjuna.ats.internal.jdbc.jndierror] Could not resolve JNDI XADataSource
            at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.createDataSource(IndirectRecoverableConnection.java:402)
            at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.(IndirectRecoverableConnection.java:119)
            at com.arjuna.ats.internal.jdbc.ConnectionImple.(ConnectionImple.java:102)
            at com.arjuna.ats.internal.jdbc.ConnectionManager.create(ConnectionManager.java:141)
            at com.arjuna.ats.jdbc.TransactionalDriver.connect(TransactionalDriver.java:93)


            Please advise.

            Thanks.

            Ketan