- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between lazy and eager loading in Hibernate
Lazy and Eager are two types of data loading strategies in ORMs such as hibernate and eclipse Link. These data loading strategies we used when one entity class is having references to other Entities like Employee and Phone (phone in the employee).
Lazy Loading − Associated data loads only when we explicitly call getter or size method.
- Use Lazy Loading when you are using one-to-many collections.
- Use Lazy Loading when you are sure that you are not using related entities.
Egare Loading − Data loading happens at the time of their parent is fetched.
- Use Eager Loading when the relations are not too much. Thus, Eager Loading is a good practice to reduce further queries on the Server.
- Use Eager Loading when you are sure that you will be using related entities with the main entity everywhere.
Sr. No. | Key | Lazy | Eager |
---|---|---|---|
1 | Fetching strategy | In Lazy loading, associated data loads only when we explicitly call getter or size method. | In Eager loading, data loading happens at the time of their parent is fetched |
2 | Default Strategy in ORM Layers | ManyToMany and OneToMany associations used lazy loading strategy by default. | ManyToOne and OneToOne associations used lazy loading strategy by default. |
3 | Loading Configuration | It can be enabled by using the annotation parameter : fetch = FetchType.LAZY | It can be enabled by using the annotation parameter : fetch = FetchType.EAGER |
4 | Performance | Initial load time much smaller than Eager loading | Loading too much unnecessary data might impact performance |
- Related Articles
- Lazy Loading in ReactJS
- Difference Between JDBC and Hibernate
- Difference between Hibernate and JPA
- Difference Between get() and load() in Hibernate
- Difference between save() and persist() in Hibernate
- Difference between sequence and identity in Hibernate
- Difference between Hibernate and Eclipse link
- Lazy loading of images in table view using Swift
- Difference Between First level cache and Second level cache in Hibernate
- Lazy Stored Procedure in Swift
- Loading and Removing Kernel Module
- Smart / self-overwriting / lazy getters in javaScript?
- Difference Between & and &&
- Which is better front loading or top loading washing machine?
- What is Loading?

Advertisements