4 Replies Latest reply on Mar 8, 2006 6:21 AM by jcerdeira

    JDBC-call in a Session-Bean does not work

    oliverroell

      Hello,

      I am working with JBoss 4.0.2 and Informix, and I want to access from a Session-Bean with a JDBC-call to the database. Thus I have done the following steps:

      a) Copied the IBM Informix JDBC Driver 2.21.JC5-file ifxjdbc.jar in the directory \server\default\lib.

      b) Created a new file named informix-ds.xml in the directory \server\default\deploy:


      <local-tx-datasource>
      <jndi-name>InformixDS</jndi-name>
      <connection-url>jdbc:informix-sqli://server:port//database:INFORMIXSERVER=server</connection-url>
      <driver-class>com.informix.jdbc.IfxDriver</driver-class>
      <user-name>user</user-name>
      password
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.InformixExceptionSorter</exception-sorter-class-name>
      <!-- sql to call when connection is created
      <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->
      <!-- sql to call on an existing pooled connection when it is obtained from pool
      <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->

      <type-mapping>InformixDB</type-mapping>

      </local-tx-datasource>


      c) Created a new business-method in the Session-Bean to connect to the database.
      At the first try I connected only to the default-database:

      Context context = new InitialContext();
      DataSource ds = (DataSource) context.lookup("java:DefaultDS");
      Connection con = ds.getConnection();
      con.close();

      This works fine.

      d) At the second try I connected to the informix-database without a connection:

      Context context = new InitialContext();
      DataSource ds = (DataSource) context.lookup("java:InformixDS");

      This works, too.

      e) At the third try I connected to the informix-database with a connection:

      Context context = new InitialContext();
      DataSource ds = (DataSource) context.lookup("java:InformixDS");
      Connection con = ds.getConnection();
      con.close();

      Now the problems begun, and the JBoss-server logged 270 error-lines to the screen. The first lines looked like the following:

      09:49:18,375 WARN [TransactionImpl] XAException: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=roell/17, BranchQual=, localId=17] errorCode=XA_UNKNOWN(0)
      org.jboss.resource.connectionmanager.JBossLocalXAException: Error trying to start local tx: ; - nested throwable: (org.jboss.resource.JBossResourceException: SQLException; - nested throwable: (java.sql.SQLException: Transactions not supported)) at org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource.start(TxConnectionManager.java:657)
      at org.jboss.tm.TransactionImpl$Resource.startResource(TransactionImpl.java:1952)
      at org.jboss.tm.TransactionImpl.enlistResource(TransactionImpl.java:548) at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.enlist(TxConnectionManager.java:436) at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:322) at org.jboss.resource.connectionmanager.BaseConnectionManager2.reconnectManagedConnection(BaseConnectionManager2.java:583) at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:450) at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:874) at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:103)

      The Swing-Client, who has connected to the bean, shows me another exception:

      org.jboss.tm.JBossTransactionRolledbackException: null; nested exception is: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=roell/17, BranchQual=, localId=17] status=STATUS_NO_TRANSACTION; - nested throwable: (org.jboss.resource.connectionmanager.JBossLocalXAException: wrong xid in commit: expected: null, got: XidImpl[FormatId=257, GlobalId=roell/17, BranchQual=1, localId=17]); - nested throwable: (org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=roell/17, BranchQual=, localId=17] status=STATUS_NO_TRANSACTION; - nested throwable: (org.jboss.resource.connectionmanager.JBossLocalXAException: wrong xid in commit: expected: null, got: XidImpl[FormatId=257, GlobalId=roell/17, BranchQual=1, localId=17]))

      f) I have added the <resource-ref> to the ejb-jar.xml and the jboss.xml:

      <enterprise-beans>

      [CDATA[Description for Access]]
      <display-name>Name for Access</display-name>
      <ejb-name>Access</ejb-name>
      access.interfaces.AccessHome
      access.interfaces.Access
      <ejb-class>access.ejb.AccessBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>

      <resource-ref>
      Informix-Database
      <res-ref-name>InformixDS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>


      </enterprise-beans>


      <enterprise-beans>

      <ejb-name>Access</ejb-name>
      <jndi-name>ejb/Access</jndi-name>

      <resource-ref>
      <res-ref-name>InformixDS</res-ref-name>
      <jndi-name>InformixDS</jndi-name>
      </resource-ref>

      </enterprise-beans>

      <resource-managers>
      </resource-managers>


      The error is the same like above. Nothing has changed after adding the resource-ref-tags.

      What's wrong with my approach? I have read a lot of tutorials and other threads, but nowhere I can find a solution for my problem.

      Would anyone help me, please?

      Regards
      Oliver

        • 1. Re: JDBC-call in a Session-Bean does not work
          oliverroell

          I have tested the JDBC-connection with the same Session-Bean with Oracle 8.1.7, and it works. A standard JDBC-connection with J2SE also works in Informix. Only JBoss cannot connect to my Informix-database. We use the Informix-version 7.2. Is this version 7.2 too old for JBoss, or is my program wrong?

          • 2. Re: JDBC-call in a Session-Bean does not work
            jcerdeira

            I have the same problem.

            and i'm in conversation with informix guys. If i have a reponse i put them here.

            And the problem is with the config of InformixDS, but i don't no what it is.

            • 3. Re: JDBC-call in a Session-Bean does not work
              gbas

              Hi, I have the same problem. JBoss 4.0.2 and Informix 9.40.

              Please help us

              • 4. Re: JDBC-call in a Session-Bean does not work
                jcerdeira

                 

                <?xml version="1.0" encoding="UTF-8"?>
                
                <datasources>
                 <local-tx-datasource>
                 <jndi-name>JNDINAME</jndi-name>
                 <connection-url>jdbc:informix-sqli://HOSTNAME:PORT/DB:INFORMIXSERVER=foo;IFX_LOCK_MODE_WAIT=-1</connection-url>
                 <driver-class>com.informix.jdbc.IfxDriver</driver-class>
                 <user-name>USERNAME</user-name>
                 <password>USERPASSWORD</password>
                 <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.InformixExceptionSorter</exception-sorter-class-name>
                
                 <metadata>
                 <type-mapping>InformixDB</type-mapping>
                 </metadata>
                 </local-tx-datasource>
                </datasources>
                


                try to put this in your data source.


                "IFX_LOCK_MODE_WAIT=-1" this is the secret

                i wope this help, for me resolved the problem