3 Replies Latest reply on Aug 26, 2004 10:48 AM by Adrian Brock

    Problem with Transaction Manager and closing datasource conn

    Steve Carter Newbie

      Hello,
      I am developing a Stateless Session EJB to access a JBoss datasource for client components of my application. The EJB delegates to a plain old java class which is the jdbc wrapper. I am using JBoss 3.2.5, MySql 4.0.12, j2sdk1.4.2_05 and the mysql-connector-java-3.1.3-beta driver. The call sequence is:

      1) pojo client --> ejb.create()
      2) pojo client --> ejb.getConnection() --> databaseWrapper.getConnection()
      3) pojo client --> ejb.getResultAsString(sql) --> databaseWrapper.getResultAsString(sql)
      4) pojo client --> ejb.closeConnection() --> databaseWrapper.closeConnection()

      I receive the stack trace at the end of this post when I leave the scope of the method pojoWrapper.getConnection() (All this does is lookup Datasource and invoke getConnection() and getStatement() which are held as references in the pojo wrapper):

      Some additional data that makes this puzzling:
      - The datasource connection is not closed until the explicit close call is made from my client code

      - If I remove the close invocation from the client code the JBoss console confirms the close method is not called on the EJB

      - sql executes successfully

      - from my debugging it appears the transaction manager performs a check on the connection cache to see if connections have been closed and this call fails consistently

      I am evaluating JBoss as a canidate for a client's integration project and I have very tight timelines. Any help or insight into this would be appreciated.

      Thanks,
      Steve

      22:40:51,609 INFO [STDOUT] Opened statement and connection
      22:40:51,609 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnect
      ion@17c8eee
      java.lang.Exception: STACKTRACE
      at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:285)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:525)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:887)
      at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:102)
      at com.tag.jboss.ds.database.DbUtilityImpl.getConnectionAndOpenStatement(DbUtilityImpl.java:66)
      at com.tag.jboss.ds.database.DbUtilityBean.getConnectionAndOpenStatement(DbUtilityBean.java:63)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:683)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
      at org.jboss.ejb.plugins.AbstractTxInterceptorBMT.invokeNext(AbstractTxInterceptorBMT.java:144)
      at org.jboss.ejb.plugins.TxInterceptorBMT.invoke(TxInterceptorBMT.java:62)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:120)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
      at org.jboss.ejb.Container.invoke(Container.java:723)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:60)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:61)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:53)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:185)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:360)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:534)
      22:40:54,614 INFO [STDOUT] Closed statement and connection


        • 1. Re: Problem with Transaction Manager and closing datasource
          Adrian Brock Master

          Stateless == no client state. You also need a user transaction.

          But what you are doing is an anti-pattern, it doesn't scale.

          • 2. Re: Problem with Transaction Manager and closing datasource
            Steve Carter Newbie

            Adrian,
            My apologies as you are correct with regards to 'Stateless == no client state' but I forgot to mention that I attempted this with a Stateful Session bean and local tx demarcation on the datasource as well and I recieved the same Stack Trace with additional Stack data. The stateful Session bean stack traces are posted at the end of this. I also notice that another current thread in this forum, 'TransactionManager - error in delist; already committed' is also exeperiencing a similar Stack Trace.

            The interesting thing is in both the Stateless and Stateful scenarios the client maintains a valid reference to the database connection even across invocations on the bean.

            As far as scalability goes, we know this is not a production architecture as we are trying to quickly show a client that their integration needs can be met with JBoss by quickly wiring up a P.O.C for them. We can talk to scalability in a J2EE env but the client wants a P.O.C as some proof that an opensource app server will fit their solution. Thanks for the heads up.

            I am not sure if there is a bug that is causing this message to appear as I have stated the database resources remain valid across invocations with bith Stateless and Stateful implementations and the code actually executes fine. We just want to follow through on this to see if their is a bug present as the facts are not making sense.

            Also, please note that the exception is being thrown in both cases from the
            the opening method invocation: org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:102)


            10:37:58,390 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnect
            ion@80fb53
            java.lang.Exception: STACKTRACE
            at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:285)
            at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:525)
            at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:887)
            at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:102)
            at com.tag.jboss.ds.database.DbUtilityImpl.getConnectionAndOpenStatement(DbUtilityImpl.java:66)
            at com.tag.jboss.ds.database.DbUtilityBean.getConnectionAndOpenStatement(DbUtilityBean.java:63)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invoke(StatefulSessionContainer.java:949)
            at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:120)
            at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
            at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(StatefulSessionInstanceInterceptor.java:273)
            at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
            at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:315)
            at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:148)
            at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
            at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
            at org.jboss.ejb.StatefulSessionContainer.internalInvoke(StatefulSessionContainer.java:416)
            at org.jboss.ejb.Container.invoke(Container.java:723)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:60)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:61)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:53)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:185)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)
            at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:360)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
            at sun.rmi.transport.Transport$1.run(Transport.java:148)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
            at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
            at java.lang.Thread.run(Thread.java:534)
            10:37:58,400 ERROR [TxConnectionManager] ResourceException while closing connection handle!
            org.jboss.resource.JBossResourceException: Error in delist!; - nested throwable: (java.lang.IllegalStateException: Already committed.)
            at org.jboss.resource.connectionmanager.BaseConnectionManager2.rethrowAsResourceException(BaseConnectionManager2.java:113)
            at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.delist(TxConnectionManager.java:493)
            at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.connectionClosed(TxConnectionManager.java:537)
            at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.closeHandle(BaseWrapperManagedConnection.java:320)
            at org.jboss.resource.adapter.jdbc.WrappedConnection.close(WrappedConnection.java:114)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.jboss.resource.connectionmanager.CachedConnectionManager.closeConnection(CachedConnectionManager.java:520)
            at org.jboss.resource.connectionmanager.CachedConnectionManager.access$000(CachedConnectionManager.java:49)
            at org.jboss.resource.connectionmanager.CachedConnectionManager$CloseConnectionSynchronization.afterCompletion(CachedConnectionManager.java:59
            2)
            at org.jboss.tm.TransactionImpl.doAfterCompletion(TransactionImpl.java:1398)
            at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:421)
            at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:456)
            at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:324)
            at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:148)
            at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
            at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
            at org.jboss.ejb.StatefulSessionContainer.internalInvoke(StatefulSessionContainer.java:416)
            at org.jboss.ejb.Container.invoke(Container.java:723)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:60)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:61)
            at org.jboss.mx.server.Invocation.dispatch(Invocation.java:53)
            at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
            at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:185)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)
            at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:360)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
            at sun.rmi.transport.Transport$1.run(Transport.java:148)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
            at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
            at java.lang.Thread.run(Thread.java:534)
            Caused by: java.lang.IllegalStateException: Already committed.
            at org.jboss.tm.TransactionImpl.delistResource(TransactionImpl.java:529)
            at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.delist(TxConnectionManager.java:486)
            ... 41 more



            • 3. Re: Problem with Transaction Manager and closing datasource
              Adrian Brock Master

              The delist message is just noise.

              You seem to have selectively ignored the key point in my previous post.