0

I have little knowledge about Hibernate. I am calling findByCriteria(DetachedCriteria criteria) method, but I noticed that it returns a List. My worry is if it will cause Java heap memory issue when the database returns very large result. In my next code, I am looping through this returned list and do something on reach record. I noticed that findByCriteria(DetachedCriteria criteria) is internally calling findByCriteria(criteria, -1, -1). Could someone enlighten me?

user3123690
  • 1,053
  • 5
  • 17
  • 27
  • What is the size of the dataset are you talking about? Did you notice it being slow? What kind of memory are we talking about? there are just so many questions.. – Praba May 27 '14 at 16:14
  • I have a table that has more than 80 columns and total records that I need to get from the database is 200,000 or may be more. My Java max heap memory is limited to 512M. – user3123690 May 27 '14 at 16:32

2 Answers2

0

That is why human created something for the pagination. Check this and this

Thai Tran
  • 9,815
  • 7
  • 43
  • 64
  • I have already read those documentations as I referred the second method in my questions. What I don't understand is if my total records is 1000 and I set maxresults to 500, how do I get rest of the 500? – user3123690 May 27 '14 at 16:25
  • you can use `setFirstResult` to set the beginning record to be queried. Both api are equals to `limit` and `offset` concept in SQL – Thai Tran May 27 '14 at 16:28
  • I have many places calling findByCriteria(criteriaObj) method inside my project. If I call both setFirstResult and setMaxResults in this particular code, will it affect other code that calling findByCriteria(criteriaObj). In other words, all other method will use same firstresult and maxresults value? I don't want to that happen. – user3123690 May 27 '14 at 17:46
  • Have you tried to use them and see what will happen? – Thai Tran May 27 '14 at 23:25
0

Apart from pagination , limiting what results you are displaying will avoid lot of data from getting into the java heap space. From my personal experience I was able to remove the issues with the memory by limiting the fields that I am displaying.

MR AND
  • 376
  • 7
  • 29