Lazy Loading VS Eager Loading
Lazy Loading What is Lazy Loading Lazy Loading loads the associated entity when you actually use it, also called a delayed loading. Features It fetches associated data when it is actually being used, not immediately. It is used to optimize performance and to reduce memory usage. It reduces the initial loading time when there are many associated entities. Example 1 2 @OneToMany(fetch = FetchType.LAZY) private List<Order> orders; Advantages Reduces initial loading time. Can reduce memory usage when there are many associated entities. Disadvantages May cause performance degradation as it fires queries every time a part of the associated entity is used. Eager Loading What is Eager Loading Eager Loading is a way to load the associated entity together when the entity is fetched, it is also called an immediate loading. ...