Skip to main content

Mini Project: Fixing the N+1 Query Problem

Learn Mini Project: Fixing the N+1 Query Problem (Performance Optimization, Spring Boot) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Mini Real-Time Project: Fixing the N+1 Query Problem Problem A page that lists authors with their books becomes slow because the code runs one query for the authors and then one more query for each author. Count the SQL statements and fix it. Requirements Map Author to many Book (lazy). Measure the number of SQL statements for the naive loop. Fix it with JOIN FETCH and measure again. Show a paged query that loads only one page. Concepts Used N+1 problem lazy loading JOIN FETCH Pageable / Page Hibernate statistics Maven Dependencies spring-boot-starter-data-jpa com.h2database:h2 Answer:...

More lessons in Performance Optimization