I am using the following piece of code to get results from DB as result set is huge.
Is it the correct way doing? I am running in to Out of memory exception and I suspect it is because of this.
// div is set to 10,000
// i have calculated how many times i need do it using a count query
// and that value is being used in iteration variable
Query bigQ=session.createSQLQuery(bigQuery);
for(int i=0;i<iteration;i++)
{
bigQ.setFetchSize(div);
bigQ.setMaxResults(i*div);
List<Object[]> result=bigQ.list();
// now i am using the result to get the values
for(Object[] a:result)
{
// rest of operations
}
}
Note:
- I have set enough Xms and -Xmx in the
jboss run.conf. - I am not able use scrollable set as the postgre driver is not supporting it.
- I can not use
createQueryas in that case hibernate is generating lots of queries, so i am using a big join query, along withcreateSQLQuery.