Java Reference
In-Depth Information
Hibernate projection queries, and JDO projection queries. Hibernate lazily loaded
properties are not that useful for the reasons we saw in chapter 6. Let's review how
each of these mechanisms can be used to improve the performance of the View
Orders query.
Using JDO fetch groups to load a subset of an object's fields
Until now we have used JDO fetch groups to eagerly load objects, but you can also
use them to load only a subset of an object's fields. To do that, you must first
define a fetch group that specifies the required fields. For example, here is a fetch
group containing fields displayed on the view orders screen:
<class name="Order">
<fetch-group name="Order.summary">
bb <field name="orderId"/>
bb <field name="status"/>
bb <field name="paymentInformation.email"/>
bb <field name="paymentInformation.phone"/>
bb <field name="restaurant.name"/>
</fetch-group>
</class>
The <fetch-group> element defines the Order.summary fetch group containing
several fields, including Order.orderId and Order.status , and the name of the
restaurant.
You then activate the fetch group by replacing the currently active fetch
groups with this one fetch group:
public class JDOOrderRepositoryImpl … {
public PagedQueryResult findOrders(int startIndex,
int pageSize,
OrderSearchCriteria searchCriteria) {
Query query = pm.newQuery(Order.class, …);
FetchPlan fp = query.getFetchPlan();
fc.setFetchGroup("Order.summary");
Collection result = (Collection)query.execute();
}
}
This code fragment calls FetchPlan.setFetchGroup() , which replaces the currently
active fetch groups with the Order.summary fetch group. The JDO implementation
 
 
Search WWH ::




Custom Search