1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)
 

Recent Questions

!!! Hibernate Frequently Asked Questions !!!

Q. What is lazy fetching in Hibernate? With Example .

!!!Answer!!!- From Technical Expert

Lazy fetching 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.
Example :
If you have a TABLE ? EMPLOYEE mapped to Employee object and contains set of Address objects.
Parent Class : Employee class
Child class : Address Class
public class Employee {
private Set address = new HashSet(); // contains set of child Address objects
public Set getAddress () {
return address;
}
public void setAddresss(Set address) {
this. address = address;
}
}
In the Employee.hbm.xml file
<set name="address" inverse="true" cascade="delete" lazy="false">
<key column="a_id" />
<one-to-many class="beans Address"/>
</set>
In the above configuration.
If lazy="false" : - when you load the Employee object that time child object Adress is also loaded and set to setAddresss() method.
If you call employee.getAdress() then loaded data returns.No fresh database call.

If lazy="true" :- This the default configuration. If you don?t mention then hibernate consider lazy=true.
when you load the Employee object that time child object Adress is not loaded. You need extra call to data base to get address objects.
If you call employee.getAdress() then that time database query fires and return results. Fresh database call.

Answered By : null Replied Date : Feb 2 2014
Answer :


Answered By : null Replied Date : Nov 27 2013
Answer :


Answered By : null Replied Date : Nov 1 2013
Answer :


Answered By : null Replied Date : Oct 24 2013
Answer :


Answered By : null Replied Date : Aug 2 2014
Answer :


Answered By : null Replied Date : Aug 4 2014
Answer :


Answered By : null Replied Date : Nov 12 2014
Answer :


Answered By : null Replied Date : Nov 30 2014
Answer :


Answered By : null Replied Date : Jul 6 2015
Answer :


Answered By : null Replied Date : Mar 22 2016
Answer :


Answered By : null Replied Date : Apr 18 2016
Answer :


Answered By : null Replied Date : Apr 19 2016
Answer :


Answered By : null Replied Date : Oct 3 2016
Answer :


Answered By : null Replied Date : Nov 6 2016
Answer :


Answered By : null Replied Date : Dec 19 2016
Answer :


Answered By : null Replied Date : May 29 2017
Answer :


 

You can also contribute to this answer:

Your Name:
Answer:

 
Ask Question and get answer from Expert.
View Answers List from Expert.

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy