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