ORM Lazy Loading Disabled, Performance Regression
After refactoring ORM relationship configurations, related entities stopped lazy loading. Now every query that accesses relationships triggers additional database queries, causing severe N+1 query problems and timeouts.
The ORM configuration was changed to eager loading for debugging but wasn't reverted, or the lazy loading annotations were accidentally removed during refactoring.
Error Messages You Might See
Common Causes
- All relationships set to FetchType.EAGER instead of LAZY
- Lazy loading disabled in ORM configuration globally
- Missing @Lazy annotation on relationship fields
- Relationship loaded outside of active transaction session
- Serialization attempt forcing full relationship materialization
How to Fix It
Set relationships to FetchType.LAZY (default). Use eager loading only for relationships always needed (profile picture, user name). Enable lazy loading in ORM config. Use @Transactional on service methods to keep session open. Load required relationships in same query with JOIN FETCH or explicit initialization.
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
When should relationships be eager loaded?
Only load eagerly if the relationship is ALWAYS used with the parent. Use explicit loading strategies (JOIN FETCH, @EntityGraph) instead.
How to fix LazyInitializationException?
Keep the database session open with @Transactional, or pre-load the relationship within the transaction using JOIN FETCH.
How to detect N+1 problems?
Enable SQL logging. Look for 1 parent query + N identical child queries. Each query executed separately = N+1 problem.