Composite Identifier Mapping

If a primary key comprises more than one column, the primary identifier can have multiple attributes mapped to these columns. In some cases, the primary key column could also be the foreign key column.

  1. Define association mappings.
  2. Migrate navigable roles of associations.
  3. Add these migrated attributes in primary identifier. The migrated attributes need not to be mapped.


In the above example, the Assignment class has a primary identifier with three attributes: one basic type attribute and two migrated attributes. The primary identifier mapping is as follows:

<composite-id>
  <key-property name="type">
    <column name="type" sql-type="smallint" 
    not-null="true"/>
    </key-property>
    <key-many-to-one name="title">
    </key-many-to-one>
    <key-many-to-one name="worker">
    </key-many-to-one>
</composite-id>