Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-1372

HIbernateContext does not work well with CachedConnectionManager

    XMLWordPrintable

Details

    Description

      I'm trying to use the HibernateContext to create an hibernate session that will be automatically flushed on JTA transaction commit. This works well but the jboss log files are getting filled with warning messages from the CachedConnectionManager. see below for a log file

      I have a simple CMT SSB that gets the hibernate session using HibernateContext, updates an object and that' s it. My code does not do any transaction management or explicit hibernate flush.

      After the method is finished, the transaction invoker will kick in and commit the transaction. Since the transaction contains some synchronization listeners, these will be notified appropriatly. Two listeners are available. One listener attached by the HibernateContext (this one will flush and close the session) and another one added by the CachedConnectionManager. This one will try to close the connection if it was not properly closed. When the hibernate listener tries to close the session, the cachedconnectionmanager will be notified that the connection is closed. This should normally remove the connection from its internal caches and also remove the automatic close on transaction termination from the current transaction. Since the connection is explicity closed, it does not need to be closed implicitly anymore.

      However, this does not work as expected (see the trace). A looked a bit in the code and the problem seems to be related to the interceptor stack. In a standard jboss installation, an ejb is configured with (among others) a transaction interceptor followed by a cachedconnectioninterceptor. The cachedconnectioninterceptor sets some context (metaAwareObject = bean) on the cachedconnectionmanager. However, in the finally block of the transaction interceptor, the cachcedconnection interceptor is already finished and the context is no longer available. This explains the 'Trying to return an unknown connection' exception. The 'Closing connection for you' message is related (i think) to the fact that the current transaction is no longer active when the cachedconnection manager is notified of the connection close. It the transaction is not active anymore, the cachedconnection manager does not remove the automatic close on transaction termination. So after the hibernate listener is finshed (connection closed), the other listener attached by the cached connection manager kicks in and closes it once more.

      I was able to get rid of all the (unnecessary) warning by simply removing the cached connection interceptor. However, i would like to keep it since it provides me basic stupidy protection.

      Attachments

        Activity

          People

            sebersole Steve Ebersole (Inactive)
            janssk1_jira janssk1 (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: