Thursday, 19 January 2017

What is lazy loading and how do you achieve that in hibernate?

Lazy setting decides whether to load child objects while loading the Parent Object.
You need to specify parent class.Lazy = true in hibernate mapping file. By default the lazy loading of the child objects is true.
This make sure that the child objects are not loaded unless they are explicitly invoked in the application by calling getChild() method on parent. In this case hibernate issues a fresh database call to load the child when getChild() is actully called on the Parent object. But in some cases you do need to load the child objects when parent is loaded. Just make the lazy=false and hibernate will load the child when parent is loaded from the database. 

No comments:

Post a Comment