Hibernate version:3.0
Name and version of the database you are using: HSQL in server mode
I am having a very large input data file of about 100,000 records and I need to operate for each record. I first tried the easiest method to call query.list() but at this line I was getting out of memory. So I changed my code to use pagination for fetching, initially it seemed to work fine but after completion of some runs it again gave me out of memory. So what I understood from this and using a profiler to see memory usage is that although the memory required did not increase in one go, but it did rose to the same level as using query.list(). My second level cache is off. I just want to know, is there any way to optimize memory usage. I have already allocated 256M of memory and can not afford to give more.
Code:
private boolean hasNextObject()
{
if(_sourceIterator != null && _sourceIterator.hasNext()){
return true;
}
return nextBatch();
}
public Object fetchNextRawObject()
{
if(hasNextObject()){
return _sourceIterator.next();
}
}
private boolean nextBatch()
{
++_fetchNo;
int dataNumber;
dataNumber = (_fetchNo - 1) * MAXIMUM_DATA_PER_FETCH;
_query.setFirstResult(dataNumber);
_sourceIterator = _query.list().iterator();
return _sourceIterator != null && _sourceIterator.hasNext();
}