-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Iteration with low memory consumption
PostPosted: Thu Feb 03, 2005 12:55 pm 
Newbie

Joined: Tue Oct 05, 2004 4:56 am
Posts: 7
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 7:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look at evict() and session.clear() for this.

also look at blog.hibernate.org which has a entry on batch processing.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.