1. More than one row with the given identifier was found: 1
org.springframework.orm.hibernate4.HibernateSystemException: More than one row with the given identifier was found: 1,
for class: com.vanroid.onebuy.entity.Order; nested exception is org.hibernate.HibernateException: More than one row with the given identifier was found: 1, for class: com.vanroid.onebuy.entity.Order
at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:218)
原因:order和stage是一对一的关系。而数据库中又存在多条数据,指向了同一个stage
Order表:
2. IllegalArgumentException
HQL的queryString 语句不正确,参数的类型不匹配
3. Found shared references to a collection org.hibernate.HibernateException
Hibernate shows this error when you attempt to persist more than one
entity instance sharing thesame collection reference (i.e. the
collection identity in contrast with collection equality).
The problem is that Hibernate supplies implementation of the
collection interfaces, for instance Set. You cannot set a collection
of entity A to a collection instance that belongs to another entity.
Assume that you have a one-to-many relation from entities A and B to
some kind items. If you try to move the items from a collection in
entity A to a collection in entity B, you will have to remove the
items from the collection of entity A before adding them to the
collection of entity B. The order of these operations is significant.
If the association is many-to-many, this will not be a problem.
总结就是:BeanUtil.copyProperties()的方式复制一个实体bean的时候,如果这个实体bean有一个集合属性,因为这个方法只是做了一个浅拷贝,所以新拷贝的实体跟旧的实体引用了同一个集合,而这在hibernate中是不允许的,所以报错。
解决方法:
拷贝后,新建一个集合,将原来的集合元素添加进去,并赋值给新拷贝的实体。