Java Reference
In-Depth Information
a many-to-one relationship with the
Seller
entity (a seller can sell more than one item,
but an item can be sold by only one seller), a one-to-many relationship with the
Bid
en-
tity (more than one bid can be put on an item), and a many-to-many relationship with the
Category
entity (an item can belong to more than one category and a category contains
multiple items). These relationships are depicted in
figure 10.7
.
Figure 10.7. The
Item
entity is related to three other entities:
Seller, Bid,
and
Category.
The relationships
to
Item
are many-to-one, one-to-many, and many-to-many, respectively.
When the
find
method returns an instance of an
Item
, it also automatically retrieves the
Seller
,
Bid
, and
Category
entities associated with the instance and populates them
entity associated with the
Item
is populated into the
seller
property, the
Bid
entities
associated with an
Item
are populated into the
bids
list, and the
Category
entities the
Item
is listed under are populated into the
categories
property. It might surprise you
to know some of these relationships are retrieved lazily.
@OneToMany
, and
@ManyToMany
annotations, have a
fetch
element to control fetch
modes, just like the
@Basic
annotation discussed in the previous section. None of the re-
lationship annotations in the following listing specify the
fetch
element, so the default
for each annotation takes effect.