Use of @Fetch(FetchMode.SUBSELECT) results in signficant memory usage in Hibernate

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 6
  • Hibernate 4

Issue

  • High volume java.lang.String memory when loading associations annotated with @Fetch(FetchMode.SUBSELECT)
  • Repeated/duplicate SQL Strings are found in memory related to subselect fetch queries

Resolution

This is a known This content is not included.issue in EAP 6 that is resolved in This content is not included.EAP 6.4.0 cumulative patch (CP) 8 and later

Root Cause

During subselect fetch queries, when a significant number of subqueries must be executed (to fetch a large number of rows) a copy is made of a portion of the original query for each subselect. If the number of subselects required to fetch the entire result set is large, the volume of String memory which accumulates can be quite large (especially for more complex SQL).

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.