HTTP Status 500 - Could not write content: failed to lazily initialize a collection of role
来源:互联网 发布:linux execl 返回值 编辑:程序博客网 时间:2024/05/19 02:39
在spring mvc中创建多对多映射类时,对应两张表分别为app和app_list,
类App, 需要添加集合:
private Set<App> mapApps = new HashSet<App>();
类AppList,需要添加集合:
@ManyToMany(mappedBy="mapApps") private Set<AppList> app_lists = new HashSet<AppList>();
在查询的时候,返回结果到页面时,出现标题所示错误。
原因是:
关联关系中采用fetch=FetchType.LAZY,返回给view层(jsp代码)的时候,由于加载领域对象的JPA Session已经关闭,导致这些延迟加载的数据访问异常。
解决办法是,在web.xml中添加OpenEntityManagerInViewFilter过滤器。
JPA:
<filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class></filter><filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
Hibernate:
<filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
参考:
Spring的OpenEntityManagerInViewFilter http://whoosh.iteye.com/blog/1300721
1 0
- HTTP Status 500 - Could not write content: failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role: com.bean.User.activities, could not initialize pro
- failed to lazily initialize a collection of role: could not initialize proxy - no Session
- failed to lazily initialize a collection of role: , could not initialize proxy - no Session
- failed to lazily initialize a collection of role:
- failed to lazily initialize a collection of role:
- failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role问题
- failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role
- failed to lazily initialize a collection of role
- 【理解JVM】JVM系列文章目录
- iOS开发之优秀的开源项目之-高仿bilibili项目
- Qt-TCP-ModBus调试笔记
- IDA Dalvik debugger: tips and tricks
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 师兄帮帮忙 Uva12412
- HTTP Status 500 - Could not write content: failed to lazily initialize a collection of role
- radio和文字对齐
- Django学习
- ActiveMQ
- 数据结构实验:连通分量个数
- MySQL 入门(六)—— 索引
- 1.2机器学习基础下--python深度机器学习
- 带指示器的ViewPager循环翻页的实现
- 一些自己的观点