hibernate异常"Found shared references to a collection"
来源:互联网 发布:php 字符串转化二进制 编辑:程序博客网 时间:2024/05/16 19:01
原文地址:http://www.blogjava.net/leekiang/archive/2008/10/31/237908.html
问题:
假定,Parent类有一个Set属性,里面放的是Son。如果查询"from Parent",某个Parent哪怕一个Son都没有,那个Set属性不会为null,而是一个空集合。
这时候如果你Parent newP=new Parent();然后BeanUtils.copyPropertis(newP,origP);最后就会报hibernate异常"Found shared references to a collection"。
注:hibernate在什么时机发现"两个对象共享一个集合"的情况的?我这边的例子是在下一次查询时发现的。
原因:
BeanUtils.copyPropertis是浅拷贝,导致这两个对象引用的Set是同一个Set,这在hibernate中是不允许的,参见Hibernate reference第6章的"Two entities may not share a reference to the same collection instance"。
这种问题常见于复制对象时。
如何解决:newP.setSonSet(null);
还有人说原因可能是并发操作:http://www.blogjava.net/fastzch/archive/2006/12/22/89520.html
参考:
http://markmail.org/message/fszouomkeicjynw2
http://blog.csdn.net/programeyonger/archive/2008/01/31/2075304.aspx
http://www.javaeye.com/topic/99505
假定,Parent类有一个Set属性,里面放的是Son。如果查询"from Parent",某个Parent哪怕一个Son都没有,那个Set属性不会为null,而是一个空集合。
这时候如果你Parent newP=new Parent();然后BeanUtils.copyPropertis(newP,origP);最后就会报hibernate异常"Found shared references to a collection"。
注:hibernate在什么时机发现"两个对象共享一个集合"的情况的?我这边的例子是在下一次查询时发现的。
原因:
BeanUtils.copyPropertis是浅拷贝,导致这两个对象引用的Set是同一个Set,这在hibernate中是不允许的,参见Hibernate reference第6章的"Two entities may not share a reference to the same collection instance"。
这种问题常见于复制对象时。
如何解决:newP.setSonSet(null);
还有人说原因可能是并发操作:http://www.blogjava.net/fastzch/archive/2006/12/22/89520.html
参考:
http://markmail.org/message/fszouomkeicjynw2
http://blog.csdn.net/programeyonger/archive/2008/01/31/2075304.aspx
http://www.javaeye.com/topic/99505
- hibernate异常"Found shared references to a collection"
- hibernate异常"Found shared references to a collection"
- hibernate异常"Found shared references to a collection
- hibernate异常"Found shared references to a collection 解决方法
- hibernate异常"Found shared references to a collection
- NHibernate异常"Found shared references to a collection"
- Found shared references to a collection
- error:Found shared references to a collection:
- HibernateException: Found shared references to a collection 解决办法
- Found shared references to a collection: com.morepower.domain.oa.TreeNode.permissions
- 使用hibernate,在面对复杂业务处理的时候,你是否很顺手,由Exception-found shared references to a collection说开去
- HibernateException Found shared references
- Hibernate JPA —— could not insert 或 detach entity passed to persist 或Found shared references 错误
- hibernate一对多映射时异常Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @Collection
- Hibernate 异常: Illegal attempt to associate a collection with two open sessions
- Hibernate 异常:Illegal attempt to associate a collection with two open sessions
- Hibernate 异常: Illegal attempt to associate a collection with two open sessions
- hibernate 懒加载异常分析: failed to lazily initialize a collection of role
- 谷歌收购摩托罗拉移动扫清障碍:获专利盾牌
- moss 无法对开始地址 <http://....> 进行爬网。
- 《AppStore审核指南》中文版
- MySQL server has gone away的几种解决办法
- 隐藏内容
- hibernate异常"Found shared references to a collection"
- winfrom 绑定TreeView的实现(三层)
- ExtJs中form表单提交的三种方式
- 高精度整数开根号算法
- Mozilla将发布Windows 8 Metro版Firefox
- Struts2 中使用<jsp:forward> 出现404
- 一些中文字体的英文名称
- 关于 oacle 锁做的 小实验
- ORACLE 学习