-->
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: One-to-many with a hybrid composite foreign key
PostPosted: Sat Jan 29, 2011 2:29 pm 
Newbie

Joined: Sat Jan 29, 2011 1:59 pm
Posts: 1
Hi,

I have two tables
Code:
Parent (PK parentId NOT NULL, FK childId1 NULL, FK childId2 NULL, ...)
Child (PK parentId NOT NULL, PK childId NOT NULL, ...)

The two nullable columns childId1 and childId2 in Parent are foreign keys to Child.childId, and the parent's primary key parentId exists in both tables. I need to map Parent-Child relationships as two one-to-many associations from Parent to Child along the (parentId, childId1) and (parentId, childId2) composite keys. I know how to map a one-to-many when the composite key is the primary key of the Parent or not a primary key of the Parent but this is a hybrid case where the composite key involves both the primary key and an additional column. And as the number of columns in the composite key is different from the number of columns in the Parent's primary key (2 vs. 1) Hibernate rejects this combination. Is this possible to map in Hibernate at all?

For completeness here's how the Java classes look:
Code:
Parent class with fields (parentId : Long, childrenInRole1 : List<Child>, childrenInRole2 : List<Child>, ...)
Child class with fields (childId : Long, parent : Parent, ...)


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.