Finding the query causing large Hibernate Session objects in a heap dump

Solution Unverified - Updated

Environment

  • Hibernate

Issue

A heap dump shows that a Hibernate Session object is using a large amount of memory. How can I find a query that is currently running for that session, to check if it is retrieving too many rows?

Resolution

In Eclipse MAT open the heap dump and:

  1. view the Dominator Tree to find the two big Hibernate Sessions
  2. run View Objects->With Incoming References on one
  3. on the from the Thread, run Java Basics -> Thread Stacks
  4. go down to the net.sf.hibernate.impl.QueryImpl frame, and the QueryImpl object
  5. inside that, go to the queryString member variable

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.