Claude Code database

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

LazyInitializationException: could not initialize proxy No session or session was closed Connection pool exhausted waiting for connections

Common Causes

  1. All relationships set to FetchType.EAGER instead of LAZY
  2. Lazy loading disabled in ORM configuration globally
  3. Missing @Lazy annotation on relationship fields
  4. Relationship loaded outside of active transaction session
  5. 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.

Milan Surelia Milan Surelia Milan Surelia is a Mobile App Developer with 5+ years of experience crafting scalable, cross-platform apps at 7Span and Meticha. At 7Span, he engineers feature-rich Flutter apps with smooth performance and modern UI. As the Co-Founder of Meticha, he builds open-source tools and developer-focused products that solve real-world problems. Expertise: ๐Ÿ’ก Developing cross-platform apps using Flutter, Dart, and Jetpack Compose for Android, iOS, and Web. ๐Ÿ–‹๏ธ Sharing insights through technical writing, blogging, and open-source contributions. ๐Ÿค Collaborating closely with designers, PMs, and developers to build seamless mobile experiences. Notable Achievements: ๐ŸŽฏ Revamped the Vepaar app into Vepaar Store & CRM with a 2x performance boost and smoother UX. ๐Ÿš€ Launched Compose101 โ€” a Jetpack Compose starter kit to speed up Android development. ๐ŸŒŸ Open source contributions on Github & StackOverflow for Flutter & Dart ๐ŸŽ–๏ธ Worked on improving app performance and user experience with smart solutions. Milan is always happy to connect, work on new ideas, and explore the latest in technology. Daniel Vรกzquez Daniel Vรกzquez Software Engineer with over 10 years of experience on Startups, Government, big tech industry & consulting. Rudra Bhikadiya Rudra Bhikadiya I build and fix web apps across Next.js, Node.js, and DBs. Comfortable jumping into messy code, broken APIs, and mysterious bugs. If your project works in theory but not in reality, I help close that gap. Taufan Taufan Iโ€™m a product-focused engineer and tech leader who builds scalable systems and turns ideas into production-ready platforms. Over the past years, Iโ€™ve worked across startups and fast-moving teams, leading backend architecture, improving system reliability, and shipping products used by thousands of users. My strength is not just writing code โ€” but connecting product vision, technical execution, and business impact. Krishna Sai Kuncha Krishna Sai Kuncha Experienced Professional Full stack Developer with 8+ years of experience across react, python, js, ts, golang and react-native. Developed inhouse websearch tooling for AI before websearch was solved : ) Yovel Cohen Yovel Cohen I got a lot of experience in building Long-horizon AI Agents in production, Backend apps that scale to millions of users and frontend knowledge as well. Franck Plazanet Franck Plazanet I am a Strategic Engineering Leader with over 8 years of experience building high-availability enterprise systems and scaling high-performing technical teams. My focus is on bridging the gap between complex technology and business growth. Core Expertise: ๐Ÿš€ Leadership: Managing and coaching teams of 15+ engineers, fostering a culture of accountability and continuous improvement. ๐Ÿ—๏ธ Architecture: Enterprise Core Systems, Multi-system Integration (ERP/API/ETL), and Core Database Structure. โ˜๏ธ Cloud & Scale: AWS Expert; architected systems handling 10B+ monthly requests and managing 100k+ SKUs. ๐Ÿ“ˆ Business Impact: Aligning tech strategy with P&L goals to drive $70k+ in monthly recurring revenue. I thrive on "out-of-the-box" thinking to solve complex technical bottlenecks and am always looking for ways to use automation to improve business productivity. Jaime Orts-Caroff Jaime Orts-Caroff I'm a Senior Android developer, currently working at Aircall. I'm open to work in various fields! Victor Denisov Victor Denisov Developer Jared Hasson Jared Hasson Full time lead founding dev at a cyber security saas startup, with 10 yoe and a bachelor's in CS. Building & debugging software products is what I've spent my time on for forever

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently 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.

Related Claude Code Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help