6.2.5. One-to-many associations
- An instance of the contained entity class cannot belong to more than one instance of the collection.
- An instance of the contained entity class cannot appear at more than one value of the collection index.
Partrequires the existence of a foreign key column and possibly an index column to the
<one-to-many>tag indicates that this is a one-to-many association.
<one-to-many class="ClassName" not-found="ignore|exception" entity-name="EntityName" node="element-name" embed-xml="true|false" />
<one-to-many>element does not need to declare any columns. Nor is it necessary to specify the
<one-to-many>association is declared
NOT NULL, you must declare the
not-null="true"or use a bidirectional association with the collection mapping marked
inverse="true". See the discussion of bidirectional associations later in this chapter for more information.
Partentities by name, where
partNameis a persistent property of
Part. Notice the use of a formula-based index:
<map name="parts" cascade="all"> <key column="productId" not-null="true"/> <map-key formula="partName"/> <one-to-many class="Part"/> </map>