Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

One to one mapping issue  RSS feed

Vaibhav Bhardwaj
Posts: 5
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

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>


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 ?

Thanks & Regards
Vaibhav Bhardwaj
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!