-->
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: Composite Key as Foreign Key inside a Composite primary key
PostPosted: Sun Mar 19, 2006 11:27 pm 
Newbie

Joined: Sun Mar 19, 2006 9:22 pm
Posts: 1
Hi guys, i am having a question regarding the following senario.
I have the following table

Code:
CREATE TABLE TBL_X (
       A_ID NUMBER(19) NOT NULL
     , B_ID NUMBER(19) NOT NULL
     , B_NUM CHAR(15) NOT NULL
     , TYPE CHAR(20) NOT NULL
     , NAME CHAR(60)
);

ALTER TABLE TBL_X 
ADD CONSTRAINT PK_X
      PRIMARY KEY (A_ID, B_ID, B_NUM);

ALTER TABLE TBL_X
  ADD CONSTRAINT FK_A
      FOREIGN KEY (A_ID)
      REFERENCES TBL_A(A_ID);

ALTER TABLE TBL_X
  ADD CONSTRAINT FK_B
      FOREIGN KEY (B_ID, B_NUM)
      REFERENCES TBL_B(B_ID, B_NUM);



So table TBL_X has a composite key (A_ID, B_ID, B_NUM), where A_ID is the primary key for TBL_A, B_ID and B_NUM is the primary key for TBL_B. I created a CLS_TBL_X_KEY class which contains an instance of TBL_A and an instance of TBL_B, e.g.

Code:
Class CLS_TBL_X_KEY {
   CLS_TBL_A a;
   CLS_TBL_B b;
}


then i have the Hibernate mapping for TBL_X as the following


<composite-id
name="key"
class="com.a.b.CLS_TBL_X_KEY"
>

<key-many-to-one
name="a"
class="com.a.b.CLS_TBL_A"
column="A_ID"
/>

<key-many-to-one
name="b"
class="com.a.b.CLS_TBL_B"
column="???????"
/>

</composite-id>

I am not sure how to map this composite foreign key inside this composite primary key.

NOTE: The Hibernate mapping xml file was generated using xDoclet.

Any help will be greatly appreciated.

regards

J Ai


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.