Demo: fixing lazy loading without Open Session in View
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
keep lazy relations working with OSIV off; prepares JNR-032-LAB1.
Draft outline details
Step by step
- Set
spring.jpa.open-in-view=false; call an endpoint that returns an entity with lazy lines. - See
LazyInitializationExceptionin the response. - Planned mistake: change the relation to
EAGER; show the extra queries everywhere. - Revert; add an entity graph or a DTO projection in the service method.
- Return a response DTO built inside the transaction; the exception is gone and the query count is low.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.