hibernate异常"Found shared references to a collection"
2011-04-09 10:49
344 查看
问题:
假定,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 3.x "org.hibernate.LazyInitializationException: illegal access to loading collection"异常解决方法
- 使用hibernate,在面对复杂业务处理的时候,你是否很顺手,由Exception-found shared references to a collection说开去
- hibernate异常"Found shared references to a collection 解决方法
- hibernate异常"Found shared references to a collection
- Exception in thread "main" org.hibernate.QueryException: illegal attempt to dereference collection
- Found shared references to a collection
- Hibernate JPA —— could not insert 或 detach entity passed to persist 或Found shared references 错误
- Found shared references to a collection: com.morepower.domain.oa.TreeNode.permissions
- error:Found shared references to a collection:
- Hibernate 3.x "org.hibernate.LazyInitializationException: illegal access to loading collection"异常解决方法
- eclipse 报错处理"undefined reference to `pthread_create’"
- warning LNK4089: all references to "SHELL32.dll" discarded by /OPT:REF
- SDK编译数学函数出错:"undefined reference to 'cos/sin'
- "undefined reference to" 问题解决方法
- warning LNK4089: all references to "USER32.dll" discarded by /OPT:REF
- undefined reference to错误 和ORA-06553: PLS-306: wrong number or types of arguments in call to "OGC_X"
- how to deal with "undefined reference to XXX"
- Pixhawk---"undefined reference to strptime"之自定义strptime函数