Hibernate: open-in-view hides N+1 rather than fixing it

Spring Boot enables it by default; it keeps the session open through rendering, so lazy loads succeed - one query at a time.

Code
// application.yml
spring:
  jpa:
    open-in-view: false      # turn it OFF and see the truth
Output
With open-in-view=true : the page renders, quietly issuing 500 queries.
With open-in-view=false: you get LazyInitializationException in development,
which is the error you wanted before shipping.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11