Java Reference
In-Depth Information
deleted when it is no longer associated with its parent object. Hibernate compo-
nents are important for two reasons:
You can use a component to map an object to its parent object's table.
You can use a collection of components to efficiently persist a unidirec-
tional one-to-many relationship that is mapped using a foreign key.
To determine whether a domain model class should be a Hibernate entity or a
component, you must carefully analyze the relationships that it has with other
classes. A class that is associated with only one other class and whose lifecycle is
dependent on that other class is a good candidate to be a component. On the
other hand, classes that have an independent existence or that are referenced by
multiple classes should be mapped as entities. Figure 6.1 is a UML class diagram
that shows some of the classes and relationships in the Food to Go domain model.
In this example, domain model classes such as PendingOrder , Restaurant , and
Order are clearly Hibernate entities. They are objects whose lifetime is indepen-
dent of any other objects. On the other hand, classes such as Address and
PaymentInformation are components because they are simple value objects with
Hibernate
Components
Hibernate
Entities
Payment
Information
Address
PendingOrder
Restaurant
PendingOrder
LineItem
MenuItem
Figure 6.1
The Hibernate entities and
components in part of the
Food to Go domain model
Hibernate Entity
Hibernate Entity
or Component
 
Search WWH ::




Custom Search