

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The key differences between hibernate's get() and load() methods, focusing on their behavior, return values, and database interactions. Get() retrieves the original object from the database immediately, while load() returns a proxy object that is initialized from the database only when accessing its properties.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Hibernate »on Sep 18, 2014 { 91 Comments } By Sivateja
one of the famous hibernate interview questions, most of us will use hibernate get and load methods irrespective of knowing their exact behavior will you accept that? of course even myself too in the initial stages Today i will try to clear that confusion.
Then what’s the difference them? lets start with load() and then get() method. Consider a Student class having 3 properties stdId, stdName, stdCountry
graphical representation…
Let me explain each point by taking an example
1 2 3 4 5
System.out.println("Student is calling with load()"); s2 =(Student) session.load(Student.class,new Integer(107)); System.out.println("Student called with load()"); System.out.println("Printing Student Name___"+s2.getStdtId()); System.out.println("Printing Student Name___"+s2.getStdName());
In index.jsp > line number 4, i have called s2.getStdtId() and hibernate simply printed 107 [at Output > line number 3] without creating any database query why? because as i have explained hibernate will prepare some fake object with given identifier value in the memory without hitting the database. So when we