5 Replies Latest reply on Jul 12, 2005 6:32 PM by Scott Li

    Getting Trying to return an unknown connection2!

    null null Newbie


      I'm using Apache OJB inside of JBoss-3.2.3.
      If I access a jdbc connection from datasource and in the same (or in RequiresNew) transaction access the database via OJB I get a

      java.lang.IllegalStateException: Trying to return an unknown connection2! org.jboss.resource.adapter.jdbc.WrappedConnection@40567be5
       at org.jboss.resource.connectionmanager.CachedConnectionManager.unregisterConnection(CachedConnectionManager.java:330)
       at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.connectionClosed(TxConnectionManager.java:539)
       at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.closeHandle(BaseWrapperManagedConnection.java:296)
       at org.jboss.resource.adapter.jdbc.WrappedConnection.close(WrappedConnection.java:117)
       at org.apache.ojb.broker.util.WrappedConnection.close(WrappedConnection.java:124)
       at org.apache.ojb.broker.util.pooling.ByPassConnection.close(ByPassConnection.java:64)
       at org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.releaseConnection(ConnectionFactoryAbstractImpl.java:79)
       at org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.releaseConnection(ConnectionManagerImpl.java:286)
       at org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl$PersistenceBrokerSyncImpl.beforeCompletion(PersistenceBrokerFactorySyncImpl.jav
       at org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl$TransactionBox.beforeCompletion(PersistenceBrokerFactorySyncImpl.java:329)
       at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1308)

      I already turned on the trace for tm and resource package. This reports for the above connection:
      2004-04-27 11:24:12,468 TRACE [org.jboss.resource.connectionmanager.CachedConnectionManager] registering connection from org.jboss.resource.connection
      manager.TxConnectionManager@3b48a8e6, connection : org.jboss.resource.adapter.jdbc.WrappedConnection@40567be5, key: org.jboss.resource.connectionmanag

      2004-04-27 11:24:12,560 TRACE [org.jboss.resource.connectionmanager.TxConnectionManager] connectionClosed called
      2004-04-27 11:24:12,560 TRACE [org.jboss.resource.connectionmanager.CachedConnectionManager] unregistering connection from org.jboss.resource.connecti
      onmanager.TxConnectionManager@3b48a8e6, object: org.jboss.resource.adapter.jdbc.WrappedConnection@40567be5, key: org.jboss.resource.connectionmanager.
      2004-04-27 11:24:12,564 INFO [org.jboss.resource.connectionmanager.TxConnectionManager] throwable from unregister connection

      I found that the key object is different.
      I would like to know what's the problem and what I can do to fix it. The problem does no occur as long as I do not mix JDBC and OJB database access. All EJB's uses container managed transaction.

      Thanks in advance, best regards,


        • 1. Re: Getting Trying to return an unknown connection2!
          Adrian Brock Master

          Your problem is that the connection is being opened in the context of the EJB
          and removed in the context of a transaction completion.

          The JBoss cached connection manager doesn't like this, it expects you to return
          the connection within the same context as you opened it.

          I don't see why OJB has to hang onto the connection until transaction completion,
          it just a bad use of resources.
          The DataSource always returns the same connection in the same transaction
          where that is necessary (e.g. it might not be necessary for interleaving on XA connections)

          One simple workaround would be to remove the CachedConnectionInterceptor
          from the EJB container definition in conf/standardjboss.xml.

          • 2. Re: Getting Trying to return an unknown connection2!
            null null Newbie


            thanks for the reply. We'll check for a solution at OJB.

            best regards,


            • 3. Re: Getting Trying to return an unknown connection2!
              Ben Brantley Newbie


              I'm having a very similar problem but with Hibernate (latest stable). The code snippet in my CMT, stateless session bean looks like this:

              try {
               session = hibernate.openSession();
               response=addStatus(session, id, statusId, userID);
               } catch (HibernateException e) {
               try {
               } catch(HibernateException ignore) {}
               log.error("HibernateException thrown:", e);
               } finally {
               try {
               log.debug("closed session for add_status");
               } catch (HibernateException ignore) {}

              Without fail, whenever that code hits the session.close() call in the finally block, JBoss spits this error.

              I'm having trouble understanding your explanation, Adrian, even though I'm sure what you're saying is right. The question is, how do I correct this behavior short of disabling the interceptor?

              Thank you,


              • 4. Re: Getting Trying to return an unknown connection2!
                Adrian Brock Master

                Moderated: Your question has been ignored it is a HIJACK.
                You are not helping the original poster.

                • 5. Re: Getting Trying to return an unknown connection2!
                  Scott Li Newbie

                  We are using OJB 1.0.0 and JBoss 3.2.3 and got the simlar problem in first round. We got that error inside a transaction block. But after looking into the code we found it related to the errors caused by using the JDBC Connection outside the OJB persist code section.

                  rs = stmt.executeQuery(sqlString);

                  To run insert query with executeQuery(sqlString) will cause exceptions and OJB is still holding the connection but EJB layer is try to roll back. When we fix the code as above, we can get through without modifiy the jboss configuration.