org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jav
来源:互联网 发布:mac开机黑屏文件问号 编辑:程序博客网 时间:2024/06/09 21:30
错误原因:
原因是在hibernate映射关系中由于延迟加载,session在调用前已经被关闭,所以加载set属性时无可用session
解决方案1(使用的是注解配置):
在
@ManyToOne(cascade={CascadeType.REFRESH, CascadeType.MERGE}, optional=true, fetch=FetchType.LAZY)
@JoinColumn(name="uim_serv_file_record_id")
private UimServFileRecord uimServFileRecord;
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="uimServFileRecord")
private Set uimServFileDatas=new HashSet();
解决方案2(使用的是xml配置):
1,把lazy=”false“
2,在web.xml中加入:(在structs的过滤器之前)
<filter><filter-name>hibernateFilter</filter-name><filter-class>org.springframework.orm.hibernate.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping><filter-name>hibernateFilter</filter-name><url-pattern>*.do</url-pattern></filter-mapping><!-- 加入上面这些 --><filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
第1种方法,就是设置为不要用lazy加载元素,这样做,虽然可以解决上面这个问题,但是会产生一些不必要的开销。比较复杂的对象对应关系,或者数据量比较 大的时候,不推荐这么做
第2种方法,就是避免session关闭过早导致出现这样的异常,这样的方法以前也是使用过,而且一般情况下filter过滤链接都会做。
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jav
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.eng
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: XXXX
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role:no sessi
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role:XXX
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cn.oa.d
- SSH报错之 hibernate.LazyInitializationException: failed to lazily initialize a collection of role: XXXX
- Hibernate:LazyInitializationException: failed to lazily initialize a collection of rol
- Hibernate问题 failed to lazily initialize a collection of role
- ejb 学习:遇到错误:LazyInitializationException.<init> : failed to lazily initialize a collection of role:
- failed to lazily initialize a collection of role: com.bean.User.activities, could not initialize pro
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection..的解决方案
- org.hibernate.LazyInitializationException: failed to lazily initialize a col
- org.hibernate.LazyInitializationException: failed to lazily initialize
- org.hibernate.LazyInitializationException: failed to lazily initialize
- failed to lazily initialize a collection of role:
- 使用CoordinatorLayout
- 《MD5加密工具类》
- 查询区间第k大 POJ2104 暴力 or 划分树 or 归并树
- Lua的require机制
- 没事刷刷题之三(简单英文题)I
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.jav
- 分享 50 个完整的 React Native 项目
- Eclipse报错Could not write metadata for '/RemoteSystemsTempFiles'.D:\Program Files\eclipse\workspace\.
- 配置_StatViewServlet配置
- tesseract-OCR识别图片中的数字
- 剑指offer面试题41_2 和为s的连续正数序列(java实现)
- Redis数据类型常用指令
- Java数组 及应用范例
- SEL和selector的简单使用