Fetch Type LAZY still causes Eager loading Hibernate Spring data

谁说我不能喝 提交于 2019-12-03 09:06:51

This is because of property spring.jpa.open-in-view=true.

As per the spring-boot-configuration Spring boot applications use spring.jpa.open-in-view=true.

With this property it

Register OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the thread for the entire processing of the request.

So in your case, subsequently when you call the getTagList() i.e., retrieve the tagList, it subsequently fires another query to fetch the tagList as the the EntityManager is still open.

As you might know, LazyInitializationException is never thrown if the entityManager that has loaded the parent is still open.

To override this, you can add spring.jpa.open-in-view=false in your application.properties/application.yml and then you should see LazyInitializationException.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!