这个是hibernate的延迟加载异常,为了不产生该异常,有如下解决方法:
1、在相应的映射文件里禁止该类的延迟加载:设置lazy=false
2、在session关闭之前取出需要的属性
3、使用openSessionInView在web.xml中插入
<filter> <filter-name>openSessionInView</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>openSessionInView</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
然后看过几篇帖子是说大系统最好不要使用openSessionInView,具体原理请看:
本文介绍了Hibernate中出现的延迟加载异常及其三种解决方案:禁用特定类的延迟加载、确保在session关闭前获取所需属性以及使用openSessionInView过滤器。同时提醒在大型系统中谨慎使用openSessionInView。
1301

被折叠的 条评论
为什么被折叠?



