could not initialize proxy - no Session
java hibernate    2017-07-19 23:47:47    1260   
lightingfire   java hibernate

因为我使用的是hibernate的注解配置,错误出在使用ManyToOne并进行级联查询的时候,我的注解配置是这样的

@ManyToOne(fetch = FetchType.LAZY,cascade=CascadeType.ALL)

原因是因为FetchType.LAZY相当于配置文件中的lazy设置为true,

解决办法就是改为

@ManyToOne(fetch = FetchType.EAGER,cascade=CascadeType.ALL)


在使用配置文件的时候也是会出现这个错误的,具体修改方式雷同,即把lazy设置为false

 


 

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/

Pre: 对权威的服从:一次逼近人性真相的心理学实验(思维导图)

Next: org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling c


Table of content