2 Replies Latest reply on Apr 9, 2009 7:09 AM by controlcho

    Unclosed connection trouble

      I'm using JBoss 5.0.1 GA with SEAM 2.1.1

      Here is my test setup:

      I have a simple stateless bean that is a SEAM component at the same time. I have the following method:

      public void testConn() {
       try {
       Connection connection = ds.getConnection();
       } catch (SQLException e) {
       e.printStackTrace();
       }
       }
      


      I'm injecting the DataSource with a @Resource annotation but I've tried getting it from the entity manager too.

      Here is what happens when I call the method:


      [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@61e76ee9
      java.lang.Throwable: STACKTRACE
       at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:278)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:524)
       at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:941)
       at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89)
      ........
      .........
      .............
       INFO [TxConnectionManager] throwable from unregister connection
      java.lang.IllegalStateException: Trying to return an unknown connection2! org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5@61e76ee9
       at org.jboss.resource.connectionmanager.CachedConnectionManager.unregisterConnection(CachedConnectionManager.java:330)
       at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.connectionClosed(TxConnectionManager.java:720)
       at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.closeHandle(BaseWrapperManagedConnection.java:362)
       at org.jboss.resource.adapter.jdbc.WrappedConnection.close(WrappedConnection.java:155)
      
      


      I've researched the subject in the wiki and gone trough the forums and I think I have an understanding of what is happening. http://www.jboss.org/community/docs/DOC-9255

      I don't want to turn CachedConnectionInterceptor off. This worked fine in 4.2.2/3
      I tried upgrading the EJB3 implementation but got the same result.

      The question is "How do I make JDBC calls and not get this error?"



        • 1. Re: Unclosed connection trouble
          jaikiran

           

          public void testConn() {
          try {
          Connection connection = ds.getConnection();
          } catch (SQLException e) {
          e.printStackTrace();
          }
          }


          You are not closing the connection. That's what the CachedConnectionManager is trying to bring to your notice.

          public void testConn() {
          Connection connection = null;
           try {
           connection = ds.getConnection();
           } catch (SQLException e) {
           e.printStackTrace();
           } finally {
           if (connection != null)
           {
           connection.close();
           }
           }
          
           }
          


          • 2. Re: Unclosed connection trouble

            Yes, I'm not closing the connection, because that was the simplest possible piece of code I came up with. I knew somebody was going to say that I'm not closing the connection.

            First I'm not supposed to close it. It's managed by the container and if you get it from the EntityManager (as I fully intend to do) it complains if you close it.

            Second even when I close the statement and/or the connection, the error still happens all the same.

            Third, this works fine with JBoss GA 4.2.2/3

            I'm still not clear on how to do JDBC calls. If somebody has any idea please do share.

            Thanks in advance.