Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hibernate needs to be able to compare and serialize identifiers. So the identifier class must be serializable, and override hashCode() and equals() consistently with the database's notion of composite key equality. </p> <p>If you have a composite id mapped as properties of the entity, the entity itself is the identifier.</p> <p>A second approach is called a mapped composite identifier, where the identifier properties named inside the &lt;composite-id&gt; element are duplicated on both the persistent class and a separate identifier class</p> <p>Finally, a composite-id may be a component class. In this case the component class is the identifier class.</p> <p>Note that it is strongly recommended to have the ID a separate class. Otherwise you will have only very awkward ways to lookup your object using session.get() or session.load().</p> <p>Relevant sections of the Reference Documentation:</p> <ul> <li><a href="http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/mapping.html#mapping-declaration-compositeid" rel="noreferrer">composite-id</a></li> <li><a href="http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/components.html#components-compositeid" rel="noreferrer">Components as composite identifiers</a></li> </ul> <p>In this example, a composite-id is mapped as properties of the entity. (The following assume you are defining the Employee class).</p> <pre><code>&lt;composite-id&gt; &lt;key-property name="EmployeeNumber"/&gt; &lt;key-property name="Dependent"/&gt; &lt;/composite-id&gt; class EmployeeAssignment implements Serializable { string getEmployeeNumber() void setEmployeeNumber( string value ) string getDepartment() void setDepartment( string value ) boolean equals( Object obj ) int hashCode() } </code></pre> <p>A mapped composite-id:</p> <pre><code>&lt;composite-id class="EmployeeAssignmentId" mapped="true"&gt; &lt;key-property name="EmployeeNumber"/&gt; &lt;key-property name="Dependent"/&gt; &lt;/composite-id&gt; class EmployeeAssignment { string getEmployeeNumber() void setEmployeeNumber( string value ) string getDepartment() void setDepartment( string value ) } class EmployeeAssignmentId implements Serializable { string getEmployeeNumber() void setEmployeeNumber( string value ) string getDepartment() void setDepartment( string value ) boolean equals( Object obj ) int hashCode() } </code></pre> <p>A component as a composite-id:</p> <pre><code>&lt;composite-id name="Id" class="EmployeeAssignmentId"&gt; &lt;key-property name="EmployeeNumber"/&gt; &lt;key-property name="Dependent"/&gt; &lt;/composite-id&gt; class EmployeeAssignment { EmployeeAssignmentId getId() void setId( EmployeeAssignmentId value ) } class EmployeeAssignmentId implements Serializable { string getEmployeeNumber() void setEmployeeNumber( string value ) string getDepartment() void setDepartment( string value ) boolean equals( Object obj ) int hashCode() } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload