Hibernate version: 2.1.7
Name and version of the database you are using: Oracle 9.2.0.5
I've got a generic question of how to iterate through a set with as less memory consumption as possible. For the application i'm developing i have to process some updates and calculations on a number of lines from one table (let's call them Transactions). These transactions, mapped with Hibernate, become quite large as they have a lot of related tables with additional information. For this list of transaction i'm now searching for a way to iterate through them without having them all in memory. The solution i have right now is using more than 400 megs for just 100 objects:
Code:
Session session = EMProperties.getInstance().getHibernateSession();
Iterator transactions = session.iterate("from Transaction t where t.currentSeverityCode > 0 and t.currentStatus='CLOSED'");
while (transactions.hasNext()) {
Transaction t = (Transaction) transactions.next();
net.sf.hibernate.Transaction tx = session.beginTransaction();
// do something with t
tx.commit();
}
session.close();
What i'm not sure is if it is ok to use just one Session for updating all objects or should i open a new session each time and close it afterwards? Also the session.iterate i'm not sure if a .find is a more performant way.
Thanks for any hints ...
Roman