We've got a rather lengthy batch process that may end up inserting a large amount of data so we've been liberally using flush and clear on the sesssion to keep memory usage down.
However, running through a profiler I noticed that we were still holding references to our inserted, updated objects after being flushed and cleared.
Traced it down to the ActionQueue class:
Code:
public void execute(Executable executable) {
final boolean lockQueryCache = session.getFactory().getSettings().isQueryCacheEnabled();
if ( executable.hasAfterTransactionCompletion() || lockQueryCache ) {
executions.add( executable );
}
if (lockQueryCache) {
session.getFactory()
.getUpdateTimestampsCache()
.preinvalidate( executable.getPropertySpaces() );
}
executable.execute();
}
Looks like since we have the query cache enabled for a few select queries that our inserts are getting cached in the executable list so that the afterTransactionCompletion method can use them.
Is there any way to have this behave a bit 'better' for our batch update case w/o having our new objects cached or do we need to make a choice of query cache enabled or disabled and live with the outcome?
We could possibly be dealing with 50, 000 to 60, 000 entities for some of our larger batches and I would prefer not to have them lingering in memory for any longer than they are needed.