This example from the documentation should give you what you need. In this case there are two objects, Person and Employee. Employee has it's own PK generated (not shown), and Person gets it's primary key based on the employee assigned to it.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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.
Code:
<one-to-one name="person" class="Person"/>
Code:
<one-to-one name="employee" class="Employee" constrained="true"/>
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:
Code:
<class name="person" table="PERSON">
<id name="id" column="PERSON_ID">
<generator class="foreign">
<param name="property">employee</param>
</generator>
</id>
...
<one-to-one name="employee"
class="Employee"
constrained="true"/>
</class>