![]() |
IT-Interview.com:Open Database for IT Professionals to share interview questions, answers and knowledge. |
![]() |
IT-Interview.com:Open Database for IT Professionals to share interview questions, answers and knowledge. |
Best Answer ! ! !
Lazy setting decides whether to load child objects while loading the Parent Object.You need to do this setting respective hibernate mapping file of the parent class.Lazy = true (means not to load child)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.Exampleslazy=true (default)Address child of User class can be made lazy if it is not required frequently.lazy=falseBut you may need to load the Author object for Book parent whenever you deal with the book for online bookshop.
Hi
Lazy fetching is related to loading of the Child objects for its parent ( In the terms of databse its primary key-foreign key relationship). In hbm.xml file you have to specify whether you want to load the child objects while loading the parent. By default hibernate doesn't load the whole child objects (lazy true ).
But Sometimes it doesn't work properly it doesn't load the child objects for the parent.and second problem is that if you have condition like ....
Employee Table -1-----n-> Emp_Dept Table<-n------1- Department Table
And you have many to many relationship between them then by specifying lazy false for both the parent object(Employee And Department) hibernate try to get all the child for this parent and for this child. Now this child becomes the parent and hibernate will try to get all the child for this parent. This process may continue.This results in performance issue.
So U have to take care while writing the mapping files in case of many-to-many relationships.
Thanks
Kuldeep
tortoise18 answered on£ºAug 19, 2009 0 comments
Simply saying: It maintains the relactionship between two tables.
ajay answered on£ºAug 20, 2009 0 comments
There are two types of Loading in application. Eager loading and Lazy
seller1111 answered on£ºAug 22, 2009 0 comments
Disadvantage is LazyInitialization exception happens when the session is not available and a lazily associated is accesed.
addictedt0u answered on£ºAug 24, 2009 0 comments
Lazy loading is the responsibility is that to load the objects for its parent
thechosen answered on£ºAug 26, 2009 0 comments