Component Primary Identifier Mapping

For more convenience, a composite identifier can be implemented as a separate value type class. The primary identifier has just one attribute with the class type. The separate class should be defined as a value type class. Component class mapping will be generated then.

  1. Define a primary identifier attribute.
  2. Define the type of the attribute as a value type class.
  3. Set the Class generation property of the primary identifier attribute to Embedded.
  4. Set the ValueType of the primary identifier class to true.
  5. Define a mapping for the primary identifier class.


In the example above, three name attributes are grouped into one separate class Name. It is mapped to the same table as Person class. The generated primary identifier is as follows:

<composite-id name="name" class="identifier.Name">
  <key-property name="firstName">
    <column name="name_firstName"
    sql-type="text"/>
  </key-property>
  <key-property name="middleName">
    <column name="name_middleName" 
    sql-type="text"/>
  </key-property>
  <key-property name="lastName">
    <column name="name_lastName" 
    sql-type="text"/>
  </key-property>
</composite-id>

Note: The value type class must implement the java.io.Serializable interface, which implements the equals() and hashCode() methods.