Running out of memory for large operation with many native SQL queries because BulkOperationCleanupAction are not freed until transaction close

Description

When running a long job which performs many SQL queries I eventually run out of memory.

This happens because the NativeSQLQueryPlan appends an action to the post-transaction action queue for each native SQL query that I run, and these cleanup operations seem to use a decent amount of memory.

There is no clear means by which these objects can be cleaned up besides closing and re-initiating a database transaction. This makes large database transactions that use native SQL queries impossible to write, without splitting them up (which in our case is not desirable).

The other workaround is to use JDBC directly.

Activity

Brett MeyerMarch 19, 2014 at 5:55 PM

If someone is available to create a test case reproducing this on ORM 4, I'll definitely re-open.

Adrian GenaidMarch 19, 2014 at 4:50 PM

I was able to reduce the memory overhead by applying an empty context to the SqlQuery (see this link for details. Otherwise the BulkOperationCleanupAction instances contain a huge list of all tables which is used to refresh all related Entities.

Nevertheless the BulkOperationCleanupAction instances are created for every update statement, which sums up to huge amount of heap space for large operations.

Adrian GenaidMarch 19, 2014 at 4:05 PM

this issue seems to be known already long time; If more information is needed to reopen the issue, I would like to provide it.

Brett MeyerOctober 30, 2013 at 9:27 AM

This type of question is best started in the user forums: https://forum.hibernate.org/viewforum.php?f=1. We typically use JIRA solely for concise, reproduceable issues with an attached test case or for new feature requests. Thanks!

Rejected

Details

Assignee

Reporter

Affects versions

Priority

Created May 13, 2011 at 1:41 AM
Updated March 19, 2014 at 5:55 PM
Resolved October 30, 2013 at 9:27 AM