I have a Java object (Object A) with an Owning Many-Many HashSet relationship to (Object B). I am using a join table with both integer ids to keep track of the relationship. Everything works perfect when I add/update the objects.
It is important to note that the Ids of the objects are not assigned by the database and are initialized at constructor time.
What I want to be able to do is to clone() this object before it gets to the database and save the cloned version. I have tried shallow cloning (implementing Cloneable and calling clone()), deep cloning (Creating new objects for everything), and using hibernate's SerializationHelper.clone() to no avail.
The reason I want to do this is because then I can put the object into the DB in its own thread without worrying about ConcurrentModification Exceptions if the object is being modified outside of the Thread as it is being persisted.
The problem I have is that the "join table" is not populated when I clone(). The entities are persisted perfectly in both Object A's and Object B's table, but the join table is left empty.
Any ideas why this might happen?
|