Java Reference
In-Depth Information
a User may exist without a BillingInfo but a BillingInfo may not exist without
a User .
9.4.2. One-to-many and many-to-one relationships
One-to-many and many-to-one relationships are the most common relationships in Enter-
prise systems. In this type of relationship, one entity will have two or more references
of another. This usually means an entity has a collection-type property such as
java.util.Set or java.util.List storing multiple instances of another entity.
Also, if the association between two entities is bidirectional, one side of the association is
one-to-many and the opposite side of the association is many-to-one.
Figure 9.7 shows the relationship between ActionBazaar Item and Bid entities. From the
Item point of view, a single Item can contain multiple Bid entities; therefore the Item-
Bid relationship is one-to-many. From the Bid point of view, multiple bids can be placed
on a single Item; therefore the Bid-Item relationship is many-to-one.
Figure 9.7. A single item may have multiple bids (one-to-many).
The type of relationship is determined by the point of view. This is different from one-
to-one relationships because in a one-to-one relationship there are only single instances of
both entities. Similar to one-to-one relationships, one-to-many and many-to-one relation-
ships do still have an owning sideā€”all relationships have one side of the relationship that's
the owner. The mappedBy attribute is used to specify the owning side. The following list-
ing shows how to code the relationship between Item and Bid .
 
Search WWH ::




Custom Search