author:zxr 2010-04-28
症状:
Caused by: org.hibernate.HibernateException: Found shared references to a collection:
at org.hibernate.engine.Collections.processReachableCollection(Collections.java:186)
at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:60)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:124)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:84)
..........
原因分析:
BeanUtil.copyProperties() 的方式复制一个实体bean的时候,如果这个实体bean有一个集合属性,因为这个方法只是做了一个浅拷贝,所以新拷贝的实体跟旧的实体引用了同一个集合,而这在hibernate中是不允许的,所以报错。
解决方法:
在拷贝后,新建一个集合,将原来的集合元素添加进去,并赋值给新拷贝的实体。