How do FetchType LAZY and EAGER differ, and what should the default be?
Short answer
LAZY loads a relation only when code touches it; EAGER loads it immediately with the parent. By default @ManyToOne/@OneToOne are EAGER and collections are LAZY. In practice: make every relation LAZY and load what each use case needs.
3 points to say:
- To-one relations are EAGER by default.
- EAGER with JPQL usually becomes N+1.
- Touching LAZY data after the session closes fails.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.