jpa 解决org.hibernate.lazyinitializationexception could not initialize proxy - no session

org.hibernate.LazyInitializationException: could not initialize proxy [org.alan.entity.SysUser#1] - no Session

 

五个解决方案

1、关闭LazyInitialization, 将fetch设成eager,可以在配置文件,也可注解

2、在spring boot的配置文件application.properties添加spring.jpa.open-in-view=true,yml同理

3、用spring 的OpenSessionInViewFilter

4、在spring boot的配置文件application.properties添加spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true

posted @ 2019-04-11 10:27  青竹玉简  阅读(1139)  评论(0编辑  收藏  举报