Found shared references to a collection org.hibernate.HibernateException

前端 未结 12 1304
一整个雨季
一整个雨季 2020-11-27 15:48

I got this error message:

error: Found shared references to a collection: Person.relatedPersons

When I tried to execute ad

12条回答
  •  余生分开走
    2020-11-27 16:00

    I had the same problem. In my case, the issue was that someone used BeanUtils to copy the properties of one entity to another, so we ended up having two entities referencing the same collection.

    Given that I spent some time investigating this issue, I would recommend the following checklist:

    • Look for scenarios like entity1.setCollection(entity2.getCollection()) and getCollection returns the internal reference to the collection (if getCollection() returns a new instance of the collection, then you don't need to worry).

    • Look if clone() has been implemented correctly.

    • Look for BeanUtils.copyProperties(entity1, entity2).

提交回复
热议问题