-->
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.  [ 6 posts ] 
Author Message
 Post subject: HELP: many-to-one mapping to a table with composite key??
PostPosted: Tue Jun 01, 2004 12:10 am 
Newbie

Joined: Thu Feb 12, 2004 4:33 am
Posts: 7
Hi Forum,

I have a table A which stores a "code" apart from aother details. The details related to the "code" like description, creation dates etc are stored in another table B having a composite id. When I map table A on column "code" to table B. It says that foreign key should have same number of columns as the primary key which is obvious. "code" column does form a part of the composite id for table B. How do i map this many-to-one relationship?

Please note that I am using Hibernate 2.0.3 and it does not have property-ref (I guess this would have been useful) for many-to-one.

Any pointers will be appreciated. TIA.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 01, 2004 3:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Since composite-id has several columns, many-to one should have a foreign key of the same structure
Code:
<many-to-one ...>
  <column name="fk1"/>
  <column name="fk2"/>
</many-to-one>

Beware to keep the same declaration order of your columns between composite-id and many-to-one

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 01, 2004 4:15 am 
Newbie

Joined: Thu Feb 12, 2004 4:33 am
Posts: 7
emmanuel wrote:
Since composite-id has several columns, many-to one should have a foreign key of the same structure
Code:
<many-to-one ...>
  <column name="fk1"/>
  <column name="fk2"/>
</many-to-one>

Beware to keep the same declaration order of your columns between composite-id and many-to-one


Does this mean that i should have all the columns forming the composite key of Table B in Table A. I am not really in a position to change the data model. Is there another work around?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 01, 2004 4:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If not, this is not a many-to-one. It is somehow a particular subset of many-to-many wo relation table, this is not supported by Hibernate and not very clean in a relational perspective

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 01, 2004 5:58 am 
Newbie

Joined: Thu Feb 12, 2004 4:33 am
Posts: 7
emmanuel wrote:
If not, this is not a many-to-one. It is somehow a particular subset of many-to-many wo relation table, this is not supported by Hibernate and not very clean in a relational perspective


Will a surrogate key for Table B help? What changes will I need in my data model?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 5:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
surrogate should solve your "table A structure can't change" issue but you'll have to update links in table A to map table B new PK.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.