4 Replies Latest reply on Oct 20, 2002 2:22 PM by genman

    NoTxConnectionManager with JDBC - how to use in container?

    genman


      I have a message-driven bean with container-managed
      transactions, that accesses the database.

      Typically, in this configuration, you
      need to use the XATxConnectionManager. However,
      I am only _reading_ from the database, and thus don't
      need the overhead of creating and destroying XID's.
      Is there some suggested work-around for this? (I
      suppose I can always just not use connection pooling.)

      What is NoTXConnectionManager used for?

      Thanks

        • 1. Re: NoTxConnectionManager with JDBC - how to use in containe
          davidjencks

          Well, a message driven bean with cmt does use xids anyway. If you were to use a jdbc 1/local tx driver the xids for the db don't get out of the jboss vm, so they have essentially no cost: you would however be committing after every message. If you use NoTxConnectionManager jboss will not attempt to enroll your connection in the tx: the connection will be left (or put) in autocommit = true state. I'm not sure this has ever been tested with an XADataSource based driver, but it works fine for jdbc 1 drivers. This should be a good solution for you.

          If you don't mind my asking... what does the mdb do if it doesn't write anything anywhere?

          • 2. Re: NoTxConnectionManager with JDBC - how to use in containe
            genman

            I'm reading routing information from the database.

            I did get NoTxConnection manager to work... yay!

            I was wondering if there was a way to use a managed
            connection from an MBean, for example, (look at the
            billing-service.xml file attached), I want to use
            the 'billing' datasource to log records to the database
            using an MBean. Periodically I get exceptions:

            Caused by: java.sql.SQLException: Connection handle is not currently associated with a ManagedConnection
            at org.jboss.resource.adapter.jdbc.local.LocalConnection.checkStatus(LocalConnection.java:774)
            at org.jboss.resource.adapter.jdbc.local.LocalConnection.checkTransaction(LocalConnection.java:755)
            at org.jboss.resource.adapter.jdbc.local.LocalStatement.checkTransaction(LocalStatement.java:771)
            at org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement.executeUpdate(LocalPreparedStatement.java:305)
            at com.proteusmobile.oamp.mdr.MdrDBAppender.logDB(MdrDBAppender.java:200)
            ... 31 more

            Is this a bug or am I configuring things incorrectly?

            I'm using Oracle, and it seems to be a "problem".

            • 3. Re: NoTxConnectionManager with JDBC - how to use in containe
              davidjencks

              Can you show some code from your mbean? The only way I know to make this happen is to use a instance variable to hold your connection and use it without synchronization. If you hold the connection in a method local variable or synchronize any method that uses the connection this should not occur.

              • 4. Re: NoTxConnectionManager with JDBC - how to use in containe
                genman

                Yes, I wrote the MBean without synchronization. Thanks for the hint.

                I "fixed" it so that connections aren't shared between threads and it works. I sort of gathered from how it was behaving that the JBoss classes weren't thread-safe. I had wondered when I wrote it if that was the intention or not.