`
lhy5201314
  • 浏览: 121104 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

hibernate异常"Found shared references to a collection"

阅读更多

问题:
假定,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.iteye.com/topic/99505

http://www.blogjava.net/leekiang/archive/2008/10/31/237908.html

分享到:
评论

相关推荐

    Hibernate Reference Documentation3.1

    Table of Contents Preface 1. Introduction to Hibernate ... Many-to-many with shared composite key attribute 23.4.4. Content based discrimination 23.4.5. Associations on alternate keys 24. Best Practices

    hibernate4.3.5references chm文档

    hibernate4.3.5references chm文档

    Hibernate References

    * 有人总以为有了关系数据库知识,就能用好Hibernate,这是认识上的误区;很多人总是先有数据表结构,然后使用Hibernate倒推类代码,这是使用上的误区,从对象模型出发才是根本之道。 * 只有真正掌握了OO面向对象...

    hibernate annotations

    NULL 博文链接:https://xiongjiajia.iteye.com/blog/1947270

    Hibernate 中文 html 帮助文档

    目录 ... 共有组合键属性的多对多(Many-to-many with shared composite key attribute) 23.4.4. Content based discrimination 23.4.5. Associations on alternate keys 24. 最佳实践(Best Practices)

    Introduction to Data Science - A Python Approach

    to provide a complete collection of references. Currently, data science is an increasing and emerging field, so readers are encouraged to look for specific methods and references using keywords in the...

    10_传智播客JPA详解_JPA中的一对多双向关联与级联操作

    10_传智播客JPA详解_JPA中的一对多双向关联与级联操作.rar

    Voltage References From Diodes to Precision High-Order Bandgap Circuits

    Voltage References From Diodes to Precision High-Order Bandgap Circuits

    Find Reference 2

    You can use this to redirect all references to TextureA (using TextureA) to TextureB, the same applied for shader, materials, mesh... Beware that replace references is very powerful yet dangerous ...

    references.zip

    references/detection/engine.py , references/detection/utils.py 和 references/ detection/transforms.py

    References.rar

    References.rar

    An Introduction to Text Mining: Research Design, Data Collection, and Analysis

    An Introduction to Text Mining: Research Design, Data Collection, and Analysis By 作者: Gabe Ignatow – Rada F. Mihalcea ISBN-10 书号: 1506337007 ISBN-13 书号: 9781506337005 Edition 版本: 1 出版日期: ...

    Spatial Data Modeller

    references to publications discussing the applications of the methods implemented in the tool. Several of the tools create output rasters, tables, or files that require the user to enter a name. ...

    hibernate笔记

    3 hibernate annotation references 5 环境准备 5 1 下载hibernate-distribution-3.3.2.GA-dist 5 2 下载hibernate-annotations-3[1].4.0.GA 5 3 注意阅读hibernate compatibility matrix(hibernate 网站download) 5...

    Hibernate参考文档

    11.2.3. 异常处理 11.2.4. 事务超时 11.3. 乐观并发控制(Optimistic concurrency control) 11.3.1. 应用程序级别的版本检查(Application version checking) 11.3.2. 扩展周期的session和自动版本化 11.3.3. 脱管对象...

    Guide to Data Structures_A Concise Introduction Using Java-Springer(2017).pdf

    This is followed by an introduction to linked lists and the implementation of stacks and queues using references. Next, there is an introduction to binary trees, a discussion of various • Chapter 1...

    Programming Language Explorations

    Each language chapter ends with a summary, pointers to open source projects, references to materials for further study, and a collection of exercises, designed as further explorations. Following the ...

    Asset Cleaner PRO - Clean - Find References

    Feature 1 - Project Cleaner: 1、Actions for unused files 2、Enhanced Project View Feature 2 - Find References: 1、Find references, usages, relationships easily in ...2、Explore usages & references

    Python Testing Cookbook (第1版)

    This cookbook is written as a collection of code recipes containing step-by-step directions on how to install or build different types of Python test tools to solve different problems. Each recipe ...

Global site tag (gtag.js) - Google Analytics