The CaveatEmptor Category can have child categories and each has items.
Categories can be nested, this is expressed as a bidirectional one-to-many
relationship that references parent and child categories.
Each Category can have many items (and an item can be in many categories). This
is a many-to-many relationship. There are four strategies how you can map it.
First, the collection items is a true many-to-many association, with
collections on both sides. There are no additional columns in the underlying
many-to-many join table.
Second, the collection categorizedItems is a one-to-many association
to an entity class CategorizedItem that represents the link. The
Item class has the same collection mapped, to make it bidirectional.
This intermediate class represents additional columns on the many-to-many
join table, such as the user who added the item to the category, and the date
of the addition.
Third, the collection categorizedItemComponents is a collection of
value typed elements, of value type CategorizedItemComponent. This
simplifies management of the link (no intermediate entity class) but allows
only unidirectional navigation. The Item class does not know anything
about this collection or the components - no shared references.
Finally, the map itemsAndUser represents the many-to-many association
with a ternary relationship using a hash map. This map has item objects as keys,
and user objects as values. The underlying many-to-many join table has three
columns, CATEGORY_ID, ITEM_ID, and ADDED_BY_USER_ID.
This strategy allows you to map an additional column (the user foreign key) of
a many-to-many join table without writing an intermediate entity or component
class.
See Also: Item See Also: CategorizedItem See Also: CategorizedItemComponent author: Christian Bauer |