Uploaded image for project: 'JBoss Enterprise Application Platform 4 and 5'
  1. JBoss Enterprise Application Platform 4 and 5
  2. JBPAPP-4579

HHH-2470 Use of session.createSQLQuery causes memory leak

    XMLWordPrintable

    Details

    • Affects:
      Release Notes

      Description

      http://opensource.atlassian.com/projects/hibernate/browse/HHH-2470
      -----------
      NativeSQLQuerySpecification fails to properly implement equals and hashcode caused by lacking implementation of hashCode and equals in all SQLQueryReturn implementations and SQLQueryScalarReturn which are members of NativeSQLQuerySpecification. I can see that NativeSQLQuerySpecification has been changed in 3.2, but the problem is still there.

      NativeSQLQuerySpecification instances are used as keys for retrieving and caching NativeSQLQueryPlan instances.

      This causes the caching-mechanism to be pretty useless when Queries created by session.createSQLQuery because new entries will be added all the time in the QueryPlanCache and the SoftLimitMRUCache member.

      So far so good, the more serious problem that is caused by this is stems from the implementation of SoftLimitMRUCache which again uses LRUMap in commons-collection. The put - method of the cache is not treadsafe, and that causes the following fragment in LRUMap to allow the map to grow beyond its maximumSize. That is bacause the containsKey method will return an incorrect result when concurrently updating the map.

      public Object put( Object key, Object value ) {

      int mapSize = size();
      Object retval = null;

      if ( mapSize >= maximumSize ) {

      // don't retire LRU if you are just
      // updating an existing key
      if (!containsKey(key))

      { // lets retire the least recently used item in the cache removeLRU(); }

      }

      retval = super.put(key,value);

      return retval;
      }

      I have included a test-case that demonstrates:

      1) Wrong implementation of equals and hashCode in NativeSQLQuerySpecification
      2) Concurrent use of LRUMap causes the map to grow beyound it's max limit
      3) Concurrent execution of session.createSQLQuery causes memory leak due to 1) and 2)

      I would be more than happy to contribute to get this fixed. Just let me know.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  stliu Strong Liu
                  Reporter:
                  stliu Strong Liu
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: