Java Reference
In-Depth Information
:Pending
Order
All requests
Update payment information
PendingOrder-Restaurant
PendingOrder-PendingOrderLineItem
: PendingOrder
LineItem
:Restaurant
Update
quantities
PendingOrderLineItem-MenuItem
Restaurant-MenuItem
:MenuItem
All requests
Figure 4.4
The relationships traversed by each request in the Place Order use case
The application only traverses the Restaurant - MenuItem relationship when han-
dling the update quantities requests and only traverses PendingOrder - Pending-
OrderLineItem when handling some requests, such as updating payment
information.
Once we have determined when each relationship is traversed, we can then
configure eager loading for some of them. We can statically configure eager load-
ing for those relationships that are always traversed and dynamically configure
eager loading for the other relationships. However, we do not want to blindly use
eager loading because that can sometimes reduce performance. For example,
eagerly loading two one-to-many relationships will create a result set containing
the Cartesian product of both relationships. If the result set is extremely large,
then it is usually better to load one of the relationships lazily. It's important to use
eager loading carefully and do a lot of performance testing.
Let's see how to configure eager loading for the Place Order use case.
Configuring eager loading statically
If we statically configure eager loading for the PendingOrder - Restaurant and Pend-
ingOrderLineItem - MenuItem relationships, then the persistence framework will always
load the related objects. It will always load the pending order's restaurant with the
Search WWH ::




Custom Search