-->
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.  [ 1 post ] 
Author Message
 Post subject: association mapping question
PostPosted: Tue Jan 30, 2007 8:00 pm 
Newbie

Joined: Wed Jan 24, 2007 6:17 pm
Posts: 3
Hi,

I'm using hibernate 3.2 with mysql 5.

I have a question concerning a mapping strategy for Associations. Say I have class A, B and C. A and B each have an unidirectional association to class C. Each A and B is associated only with one Object of type C, but each C Object can be associated by any number of A and B objects.
A or B objects can be initialized with persistent or detached C Objects.

I wonder which mapping best fits my needs here.

Option 1) which came first in my mind was to use a <many-to-one> association. This works fine so far - using cascade="save-update" also the creation of the C entries in the C table is done by hibernate. When a transient A object holding a reference to a already persistent C Object, the C Object is not saved twice, but the now persistent A object has a oreign key to the already existing C entry in teh db. This is fine so far - only problem is with removing - I need something like a garbage collector that delets all C objects that are not associated to any A or B object. Is there a way to accomplish that with hibernate?? If not what is the best way of implementing that? database Triggers are probaly better than writing that in Java I guess - any other ideas?

Then I thought about Opion 2), using a <one-to-one> mapping. The problem here is again with saving a A or B object with a reference to a persistent C object. With cascade="all", the C object is not saved again and hence, the newly created A or B object has no associated C Object when retrieved from the database.

Can anyone contribute something to this issue? Help would be greatly appreciated.

Thanks,

Hans Peter


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

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.