Java Reference
In-Depth Information
<class name="Order">
<fetch-group name="Order.summary">
bb <field name="orderId"/>
bb <field name="status"/>
bb
bb <field name="restaurant.name"/>
</fetch-group>
</class>
The <fetch-group> element defines the Order.summary fetch group that consists of
fields, including Order.orderId and Order.status , and the name of the restaurant.
Here is how you would execute a query that uses this 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.addGroup("Order.summary");
Collection result = (Collection)query.execute();
}
}
This code fragment configures the query to use the Order.summary fetch group.
The JDO implementation will retrieve the orders and their restaurants by execut-
ing this query using a SQL SELECT statement that does a join between the
FTO _ORDER and RESTAURANT tables and returns only those columns that corre-
spond to the fields in the fetch group. Note, however, that you might need to con-
figure eager loading using a vendor-specific mechanism such as Kodo JDO 3.3's
per-field fetch mechanism if you are using a JDO implementation that does not yet
support the JDO 2.0 standard. In section 11.4, we will look at an implementation
of the OrderRepository that uses Kodo JDO' s per-field fetch mechanism to opti-
mize object loading.
Using Hibernate fetch joins
Hibernate provides fetch joins for eagerly loading objects when executing a
query. An application uses a fetch join in a criteria query by calling Crite-
ria.setFetchMode() . This method takes two parameters that specify the name of
 
 
Search WWH ::




Custom Search