开发者

Can't fetch more than 50000 records in hibernmate HQL List

开发者 https://www.devze.com 2023-03-13 14:49 出处:网络
I\'m using struts hibernate. I have one table which have more than 50K records, but I can\'t fetch that records in arraylist, when I try, it always fire me java heap space exception- Out of memory.

I'm using struts hibernate.

I have one table which have more than 50K records, but I can't fetch that records in arraylist, when I try, it always fire me java heap space exception- Out of memory.

What's开发者_C百科 this problem in that?


You already have the answer: you'll either need more heap space, more RAM, or fewer records.

You can try increasing the memory available to your JVM, but a better question is: Why do you need to query for 50K records?

If you're processing them in Java, perhaps a strategy that does the calculations on the database would be a better idea.

Your clients certainly don't need to look at 50K records at once. Google might get millions of hits, but they prioritize them and send you the top 25 at a time. Your app should emulate that strategy.


If you just need to process one entity at a time (e.g. for writing all entities to an export file), you may want to look at how you can stream results in Hibernate.

The following link points to a article talking about this topic in the context of NHibernate, but the solution should be applicable for Hibernate as well: http://ayende.com/blog/4548/nhibernate-streaming-large-result-sets

0

精彩评论

暂无评论...
验证码 换一张
取 消