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
----淡定从容,宁静致远----