I am using pg74.216.jdbc3.jar driver to access PostgreSQL db. I try to select all records in a table which has 100,000 records to inspect the performance with setFetchSize() mechanism.
My code like this:
Code:
public static void pagingSelect(int fetchSize, int displayCount){
Session session = ConnectionBean.getCurrentSession();
Query query = session.createQuery("from Customer");
query.setFetchSize(fetchSize);
System.out.println("Start loading...");
Iterator customerIterator = query.list().iterator();
int i = 0;
while (customerIterator.hasNext()) {
Customer customer = (Customer)customerIterator.next();
System.out.println(customer.getId() + ",\t" + customer.getCompany());
i++;
if (i == displayCount)
break;
}
session.close();
System.out.println("End loading.");
}
But when it is running query.list().iterator(), it takes a several minutes and raise OutOfMemory error. Obviously, setFetchSize() doesn't takes effect.
I have already set
lazy="true" in Customer.hbm.xml mapping file.
What's wrong for this? Thank you very much.
--
Best regards,
Diviner.