• Post Reply Bookmark Topic Watch Topic
  • New Topic

Lazy loading in JPA(Hibernate)

 
Java Blackbelt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding lazy loading in hibernate :

Say I have a following entity :



It is obvious from the code that collection of child will be lazily loaded.
Assume In database each parent have million records of child.

Assuming session is open and childs are accessed from parent, how hibernate deals with memory issue?
Does it fire batch queries..if yes..lets say it retrieves first batch of 100 out of million records ,then does it mean that there are 99 entity and 1 proxy at last to retrieve next 100(Just my thoughts).

Any help will be highly appreciated !!
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate doesnt deal with memory issues for you!
If you have a million children in the DB and try load the collection Hibernate will try to load all the records
and if you dont have enough memory you will end up with OutOfMemoryException.

You have to make sure yourself you have enough memory to load all the data that you need.
If that's not the case you need to implement yourself the logic to load the chunks of data that suit your memory.
Hibernate doesnt do it transparently for you.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!