<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    javax.resource.ResourceException: Some connections were not closed
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/feijtel">Leon Feijtel</a> in <i>Datasource Configuration</i> - <a href="https://community.jboss.org/docs/DOC-17543">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Yesterday I was investigating a &ldquo;Connection is not associated with a managed connection&#8221; error that occurred in our application. Browsing through the log files, I discovered that we accidentally leaked a connection when retrieving data from the database failed.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The following happened:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>A ClassCastException occurred while Hibernate was resolving a ManyToOne relationship. One of the classes involved was not Serializable. Because the error handling in our application did not close the session, JBoss cleaned up for us and the CachedConnectionManager reported: Closing a connection for you.&#160; Please close them yourself.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Obviously, this means there are two errors in the application. One of the classes needed to be Serializable, and our error handling wasn&rsquo;t closing the session properly. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>However, straight after that another error was shown in the logging:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ol style="list-style-type: lower-alpha;"><li><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">javax.servlet.ServletException</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">: Error invoking cached connection manager</span></li></ol><p><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">&#160;&#160;&#160;&#160;&#160; at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(</span><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">CachedConnectionValve.java:174</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">)</span></p><p><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">&#160;&#160;&#160;&#160;&#160; at org.apache.catalina.core.StandardEngineValve.invoke(</span><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">StandardEngineValve.java:109</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">)</span></p><p><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">&#160;&#160;&#160;&#160;&#160; at org.apache.catalina.connector.CoyoteAdapter.service(</span><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">CoyoteAdapter.java:330</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">)</span></p><p><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">&#160;&#160;&#160;&#160;&#160; at org.apache.coyote.http11.Http11Processor.process(</span><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">Http11Processor.java:829</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">)</span></p><p><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">&#160;&#160;&#160;&#160;&#160; at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(</span><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">Http11Protocol.java:598</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">)</span></p><p><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">&#160;&#160;&#160;&#160;&#160; at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(</span><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">JIoEndpoint.java:451</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">)</span></p><p><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">&#160;&#160;&#160;&#160;&#160; at java.lang.Thread.run(</span><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">Thread.java:662</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">)</span></p><p><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">Caused by: </span><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">javax.resource.ResourceException</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">: Some connections were not closed, see the log for the allocation stacktraces</span></p><p><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">&#160;&#160;&#160;&#160;&#160; at org.jboss.resource.connectionmanager.CachedConnectionManager.popMetaAwareObject(</span><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">CachedConnectionManager.java:251</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">)</span></p><p><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">&#160;&#160;&#160;&#160;&#160; at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(</span><span style="text-decoration: underline;"><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;">CachedConnectionValve.java:164</span></span><span lang="EN-US" style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">)</span></p><p>&#160;&#160;&#160;&#160;&#160; <span style="font-size: 10.0pt; font-family: 'Courier New'; color: black;">... 6 more</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This confuses me a little. JBoss detects that we left a connection open (we have the properties &#8216;debug&rsquo; and &#8216;error&rsquo; both set to true in the jca-jboss-beans.xml), but it seems that when JBoss tries to close it, something else goes wrong. Why closing fails, I do not know. The ResourceException says &ldquo;see the log file for allocation stacktraces&#8221;, but I&rsquo;m not sure what to look for?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>After all of the above, the Hibernate Session object thinks its session object and connection are still in good shape. The session.isOpen() and the session.isConnected() both return true. However, the underlying JDBC connection isn&rsquo;t there anymore. Any attempt to use the Session object afterwards results in the &ldquo;Connection is not associated with a managed connection&#8221; error mentioned above.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>We are using JBoss 5 and Hibernate 3.2. We plan to upgrade Hibernate to a new version, but haven&rsquo;t been able to find the time. So I'm stuck for now with this version.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I realize our application contains a serious error by not closing the session, and that that is the area that needs to be fixed. But I&rsquo;m trying to understand how it&rsquo;s possible that closing the connection fails and how it&rsquo;s possible that Hibernate still thinks everything is ok, while the underlying JDBC connection has been closed/destroyed. Shouldn't JBoss signal that the connection close failed and inform Hibernate?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Any help is appreciated. </p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="https://community.jboss.org/docs/DOC-17543">going to Community</a></p>

        <p style="margin: 0;">Create a new document in Datasource Configuration at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2077">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>