I’m new on object persistence with Hibernate. I’m reading a book to try to understand what’s the difference between lazy set to false, eager and immediate fetching but I don’t see any difference. Any help??
Thanks in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I believe “immediate” is a synonym for “eager” (Eager being the JPA, which Hibernate implements, definition)
Lazy is as it sounds. Don’t do anything until you have to. Eager means … as it sounds.
If Foo has a Collection, and you set it to lazy, then only when you need the contents fo that collection are the selected, loaded, etc. whereas if it is eager, it will load the Bars at the time it loads Foo. This can be problematic if you eagerly load a collection of entities that eagerly load a collection of entities, and so on.
However, if you make everything lazy, then you may suffer from excess queries and round trips. You have to choose what is right for how you will be using the entity.
Start with lazy if you want a one-line rule of thumb..