Hibernate not throwing LazyInitializationException in Spring Boot Project

I am working on a Spring boot project with Hibernate 5.0. Unfortunately, Hibernate reads lazy initialized objects without throwing a LazyInitializationException even after a transaction is committed. How to enable LazyInitializationException outside of transactions?

(The current behavior hides errors in the code.)

+3
source share
1 answer

Spring boot has the spring.jpa.open-in-view property with a default value of true. This will register an OpenEntityManagerInViewInterceptor , which will save the transaction for the entire request.

try adding this to the application.properties file:

 spring.jpa.open-in-view=false 

Discussion of this issue on GitHub

Some documentation on Spring Boot Properties

Hope this helps!

+5
source

Source: https://habr.com/ru/post/1274345/


All Articles