Hello friends,

I want to tell all of you with joy to now I am going to start with Hibernate tutorial to easy steps to learn about basic topics and believe me it really helps you to learn about hibernate.  So today we see the very important topic so let start the session –


What is the Difference between Lazy loading and Eager loading approach.

  • Lazy loading is much faster than Eager loading because initial load time of Lazy loading is much smaller than Eager loading approach.
  • Lazy loading is fetched when it needs but Eager loading fetch immediately.
  • By default, the lazy loading fetch type is select unless you explicitly mark Eager loading fetch type by hibernate.
  • Lazy loading is less memory consumption than Eager loading approach.
  • In Eager loading approach too much unnecessary data might impact performance but in Lazy loading approach its load only according to you need.


For Example:-

Suppose there is two entity first one is University and the second one is a Student and there is a relationship between them. Both entities might have same basic properties. If University entity has id, name, address as well as a property called students. let see the flowing example:-


After mention the above example now when you need to load the University from the database, hibernate loads its id name and address field for you. But there are two choices you have to load student class:-

a) Fields of Student class also load at the time of loading University fields together is called as eager loading approach.

b) And if you want to load fields of Student class on demand that kind of loading is called as Lazy loading approach.

Thanks for reading.