-->
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: Problem iterating through large query results
PostPosted: Wed Apr 13, 2005 1:51 pm 
Newbie

Joined: Mon Dec 15, 2003 3:34 pm
Posts: 18
Hi folks

I'm facing a severe situation with the following:

I must query thousands of objects and iterate through them all to do certain processing with each instance.

To achieve this I created a query:

Code:
Query query = session.createQuery("from Bill as b where b.date = ?");
query.setParameter(0, new Date());
Iterator results = query.iterate();


Then, for each iteration I must also create and persist a new instance of another bean:
Code:
while (results.hasNext()) {
   // do my processing ...
   Payment payment = new Payment();
   // set some payment's attribuites
   session.save(payment);
}


The first problem is that every instance loaded goes to the first level cache increasing the memory usage (about 62MB) until I get an OutOfMemoryException. To solve this I tried to evict each instance from the cache after using it, calling session.evict(), but the memory allocation continues to increase, though in a smaller rate (about 29MB), as I observed in W2K Task Manager.

The second problem is that the new instances of Payment also go to the cache and I would have the same problems to evict them.

Any comments will be wellcome.

Thanks.

_________________
Gabriel C. Oliveira
Sumersoft Technology, Brazil


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 15, 2005 10:55 am 
Newbie

Joined: Mon Dec 15, 2003 3:34 pm
Posts: 18
Hi again

I found a memory leak in my example:

The Bill bean had a many-to-one association with another bean and no "cascade" parameter in the mapping file. Once I specified cascade="all" for such association, evict() started to remove both objects from the first level cache keeping the memory usage stable.

_________________
Gabriel C. Oliveira
Sumersoft Technology, Brazil


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.