Hibernate is not throwing LazyInitializationException in Spring Boot Project

前端 未结 1 1535
清酒与你
清酒与你 2021-01-12 11:41

I work on a Spring Boot project with Hibernate 5.0. Unfortunately Hibernate reads the lazy initialized objects without throwing LazyInitializationException even

相关标签:
1条回答
  • 2021-01-12 12:32

    Spring boot have a property spring.jpa.open-in-view with a default value of true. This will register a OpenEntityManagerInViewInterceptor that will keep the transaction alive for the entire request.

    try adding this to your application.properties file:

    spring.jpa.open-in-view=false
    

    A discussion about it on GitHub

    Some documentation about Spring Boot properties

    Hope it helped!

    0 讨论(0)
提交回复
热议问题