What is the difference between FetchType.EAGER and FetchType.LAZY?

FetchType.EAGER and FetchType.LAZY control when JPA loads an entity's related data -- EAGER loads the associated entity or collection immediately, in the same query or a follow-up query right away, while LAZY defers loading the association until it's actually accessed in code.

Key Points

Example

An Order entity's list of OrderItems is typically mapped LAZY since not every use case needs the items, but a specific "order details" screen that always needs both the order and its items can use a JOIN FETCH query to eagerly load them in one round trip just for that case.

@Entity
public class Order {
    @Id @GeneratedValue
    private Long id;

    @OneToMany(mappedBy = "order", fetch = FetchType.LAZY)
    private List<OrderItem> items;
}

// Eagerly fetch just for this query, without changing the default mapping
@Query("SELECT o FROM Order o JOIN FETCH o.items WHERE o.id = :id")
Order findByIdWithItems(@Param("id") Long id);

Common Mistakes

Follow-up Questions

Interview Tip

A concise interview answer is

EAGER loads the related entity or collection immediately along with the parent, while LAZY defers loading until the association is actually accessed, using a proxy. I default associations to LAZY to avoid loading data I don't need and to prevent N+1 problems, then use a JOIN FETCH in specific queries when I know I'll need the related data eagerly for that particular use case.

Last updated: 11 November 2026

Previous question: What does the @Transactional annotation do in Spring?

Next question: What is the @Id annotation used for?

More Spring Data JPA interview questions

All Spring Data JPA questions