Complete Example Reproducing "Found shared references to a collection"?
posted 5 years ago
Is there any complete (small) example showing how to reproduce the "found shared references to a collection" with JPA2 and Hibernate?
I have tried the example here: https://forum.hibernate.org/viewtopic.php?p=2273553 However, without luck (or errors).
Is this problem something that has been addressed in a later version (3.6) of Hibernate?
Thanks in advance!
A couple of notes, in case someone else stumbles upon this:
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.
I finally managed to write a small example program reproducing the problem and can post it upon request.