Java Reference
In-Depth Information
pending order and load a line item's menu item with the line item. This means, for
example, that when the application handles a request to update the payment infor-
mation, the persistence framework will execute the following SQL statements:
select …
from PENDING_ORDER po
left outer join RESTAURANT r
on po.RESTAURANT_ID=r.RESTAURANT_ID
where po.PENDING_ORDER_ID=?
select …
from PENDING_ORDER_LINE_ITEM li
left outer join MENU_ITEM mi
on li.MENU_ITEM_ID=mi.MENU_ITEM_ID
where li.PENDING_ORDER_ID=?
The first statement does a join between the PENDING_ORDER and RESTAURANT
tables and the second does a join between the PENDING_ORDER_LINE_ITEM and
MENU_ITEM tables. This is considerably more efficient than what we achieved
with the default settings. By making only two small changes to the ORM document
we were able to replace several SELECT statements with two SELECT statements.
However, we can do even better by configuring eager loading dynamically.
Configuring eager loading dynamically
By dynamically configuring eager loading for each request, we can often get the
persistence framework to load more objects with each SELECT statement. For
example, with the update payment information request we can configure the per-
sistence framework to eager load the PendingOrder - PendingOrderLineItem rela-
tionship in addition to the PendingOrder - Restaurant and PendingOrderLineItem -
MenuItem relationships. The persistence framework will then execute a single SQL
SELECT statement that does a join between the PENDING_ORDER , RESTAURANT ,
PENDING_ORDER_LINE_ITEM , and MENU_ITEM tables.
select *
from FTGO_PENDING_ORDER po
left outer join FTGO_RESTAURANT r
on po.RESTAURANT_ID=r.RESTAURANT_ID
left outer join FTGO_PENDING_ORDER_LINE_ITEM li
on po.PENDING_ORDER_ID=li.PENDING_ORDER_ID
left outer join FTGO_MENU_ITEM mi
on li.MENU_ITEM_ID=mi.MENU_ITEM_ID
where po.PENDING_ORDER_ID=?
As you can see, by using eager loading we have replaced several SELECT statements
with a single SELECT statement. The details of how you dynamically configure
 
Search WWH ::




Custom Search