-->
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.  [ 1 post ] 
Author Message
 Post subject: Reducing memory usage or how to get not all results at once
PostPosted: Tue Jul 28, 2009 12:07 am 
Newbie

Joined: Thu Aug 28, 2008 8:14 pm
Posts: 2
Location: New Zealand
Hello,

I have following problem that I couldn't solve by google or testing yet:

I have to process all entities from a relationship. The number of entities is around 15.000 and I have to go through all of them. The used memory after loading them rises by about 100MB and it is foreseeable that this is a risk of an OutOfMemory exception, if the number of entities rises further. I'm now looking for a way to iterate over the entities without produciong too much load on memory or the database.
the first idea was to use Query.iterate(), but the API description for Query.iterate() says
Quote:
Entities returned as results are initialized on demand. The first SQL query returns identifiers only.

This sounds like each time In call next() on the iterator it would execute a query (SELECT ... FROM ... WHERE ID = ...). I hope that I'm wrong.

A colleague suggested to use fetchSize and cacheMode to improve that, but fetchSize doesn't help if Query.list is actually returning the complete list of objects as ArrayList. And I haven't found any useful documentation about the CacheModeType enum.

So what is the best practice way to get a stream of entities back from Hibernate/JPA without hammering the database and skyrocketing the memory?

Cheers,
SF


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

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.