I’m using a StatelessSession to read and process millions of entries.
Surprisingly (to me) the StatelessSession is backed by a StatefulPersistenceContext which is getting filled up with entries, eventually using up all the memory.
Is there a “best way” to flush/clear the StatefulPersistenceContext?
There is no way through the StatelessSession interface.
I’m using Hibernate 5.1.10.Final (through GORM 6.1.8)
The temporaryPersistenceContext is defined like this:
private PersistenceContext temporaryPersistenceContext = new StatefulPersistenceContext( this );
And, after every operation, it’s cleared:
@Override
public List list(String query, QueryParameters queryParameters) throws HibernateException {
checkOpen();
queryParameters.validateParameters();
HQLQueryPlan plan = getQueryPlan( query, false );
boolean success = false;
List results = Collections.EMPTY_LIST;
try {
results = plan.performList( queryParameters, this );
success = true;
}
finally {
afterOperation( success );
}
temporaryPersistenceContext.clear();
return results;
}
If you have a use case where this one is not cleared, you should create a replicating test case and open a Jira issue with the test case attached to it.