-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate, Cloning, and a Relationship
PostPosted: Thu Feb 05, 2009 3:37 pm 
Newbie

Joined: Tue Jul 22, 2008 5:11 pm
Posts: 16
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?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 5:28 pm 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
I think that may not be a good idea.

Surely you're better off preventing access to your objects from other threads while they are being persisted.

--
Stephen Souness


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.