Hibernate one-to-one mapping with a reference column (XML mapping)

Prashanth Shyamprasad picture Prashanth Shyamprasad · Feb 4, 2013 · Viewed 24.3k times · Source

I have a user table and a user_detail table with one to one mapping user_detail table have a field user_id to be used for this relation which stores id field value of corresponding user.

How to write the hibernate hbm file for this relation?

UPDATE

what my problem is that user's primary key is id , user_detail's foreign key is user_id

all the examples i got in internet users user_id as users primary key and the same as foreign key in other table

Answer

EGo X picture EGo X · Apr 7, 2015

In the User.hbm you need to declare the relation with UserDetails like this:

<one-to-one name="user_detail" foreign-key="user_id" class="UserDetail full name "/>

Hope this help you