Skip to content
Ameen Abozaid
Planned lessonJNR-032-L06

Demo: catching N+1 with a query-count test

  • Lesson 6 of 7
  • Junior
On This Lesson 3 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

write a test that fails when queries multiply; prepares JNR-032-LAB1.

Draft outline details

Step by step

  1. Seed 100 orders with lines in a test.
  2. Add a query counter (Hibernate statistics or a datasource-proxy library; verify your choice).
  3. Call the order-history endpoint and print the count: 101.
  4. Write the assertion queryCount <= 2; the test fails.
  5. Planned mistake: add fetch = EAGER and show the count is still high; revert it.
  6. Add the join fetch or entity graph; the test passes.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.