1 Reply Latest reply: Apr 26, 2012 3:24 AM by Adam Warski RSS

Foreign key mapping in hbm.xml file

Vaibhav Bhardwaj Newbie

Hi,
I need help on hibernate mapping.
I have a table “A” having primary key “A_ID”. And this “A_ID” primary column of table “A” is foreign key as well as primary key both in table ”B” .
That is “A_ID” is primary as well as foreign key (referencing table ”A”) in table “B” .

 

And “A_ID” in table “A” is created using a sequence “UNIQUE_ID_SEQUENCE”.

 

So my doubt is while making A.hbm.xml , I will be mapping primary key column “A_ID” of table “A” something like this

 


A.hbm.xml:
Correct me if I am wrong anywhere …
<id name="aid" type=”int” column="A_ID" >
<generator class="sequence">
<param name="sequence">UNIQUE_ID_SEQUENCE</param>
</generator>
</id>

 

B.hbm.xml

 


How will I be mapping primary key here ? Same as above ?

 

And moreover as A_ID is foreign key as well primary key in table “B” then should I provide foreign key mapping in B.hbm.xml also (provided the same column “A_ID is mapped as primary key also in B.hbm.xml”) ?
And what about using sequence inB.hbm.xml ?

 

Table A and table B are mapped one-to-one.

 

 

 

Thanks & Regards
Vaibhav Bhardwaj