Skip to content
Ameen Abozaid
Planned lessonJNR-032-L05

Open Session in View: why to turn it off

  • Lesson 5 of 7
  • Junior
On This Lesson 4 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

understand and disable Open Session in View (OSIV).

Planned topics

  • OSIV keeps the persistence context open until the HTTP response is written.
  • It hides LazyInitializationException, but lets queries run in controllers and JSON serialization.
  • That means unplanned N+1 and a database connection held for the whole request.
  • Spring Boot enables it by default (with a startup warning).
  • Set spring.jpa.open-in-view=false and load data explicitly in services.
Draft outline details

Demonstration

yaml
spring:
  jpa:
    open-in-view: false

Check your understanding

What does OSIV hide?

Show answer

Lazy loading outside the service layer.

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.