-->
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: Cascade to many-to-many association table with composite id?
PostPosted: Fri Apr 20, 2007 11:58 am 
Newbie

Joined: Wed Apr 18, 2007 4:10 pm
Posts: 3
We have a logical many-to-many relationship between Person and Address, with a PersonAddress association entity in between.

As recommended (and the arguments provided do make sense!) by the Hibernate information reviewed so far (ref. doc. on Hibernate.org, HIA, JPwH, this forum, etc.), we are implementing the above logical many-to-many relationship as two one-to-many ones.

And as seems a common practice (if not a recommendation --a couple of places say that this is "quite arguable", if memory serves--, and although it makes sense, at least initially --e.g. until you start thinking about history--), the PersonAddress has a composite id (natural key) containing the personId and addressId.

Now, we would like to cascade inserts (in fact, all CRUDs) in the database from Person to PersonAddress, but:
* since Person.personId is generated it is not available before flushing;
* since PersonAddress.personId is however assigned it must be available before flushing...

This contradiction seems impossible to reconcile? Reason for which I've been recommending to use a surrogate key on PersonAddress as well. This is also consistent with the common realization that association tables typically end up with data of themselves, i.e. that a table is a table and flagging some as "association" tables is an artificial and problematic inconsistency.

In other terms (and DBAs allowing...), ALL tables should have surrogate keys to follow the many-to-many (and other) recommendation(s) all the way through and try to keep things consistent, simple, flexible, etc.

But I am interested in any thoughts on the above!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 10:02 am 
Newbie

Joined: Wed Apr 18, 2007 4:10 pm
Posts: 3
Hello all,

I am still interested in any ideas or pointers confirming or challenging the thoughts below.


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.