primary key associations
unique foreign key associations
Primary key associations don't need an extra table column; if two rows are related by the association then the two table rows share the same primary key value. So if you want two objects to be related by a primary key association, you must make sure that they are assigned the same identifier value!
For a primary key association, add the following mappings to Employee and Person, respectively.
Now we must ensure that the primary keys of related rows in the PERSON and EMPLOYEE tables are equal. We use a special Hibernate identifier generation strategy called foreign:
A newly saved instance of Person is then assigned the same primar key value as the Employee instance refered with the employee property of that Person.
Alternatively, a foreign key with a unique constraint, from Employee to Person, may be expressed as:
And this association may be made bidirectional by adding the following to the Person mapping: