5.5. Fetch Group Element

Fetch groups are sets of fields that are loaded together. You may recall that a field can use the default-fetch-group attribute to control whether it is in the default fetch group. JDO also allows you to create other fetch groups. As you will see in Chapter 12, FetchPlan, you can use fetch groups in conjunction with JDO's FetchPlan interface to fine-tune data loading.

You create fetch groups with the fetch-group metadata element. This element goes within the class element, after all field elements. Classes can define multiple fetch groups. The fetch-group element has the following attributes:

[Note]Note

Kodo also reserves fetch group names beginning with ejb or kodo.

Each fetch-group contains field elements. As you might expect, listing a field within a fetch-group includes that field in the fetch group. Each fetch group field can have the following attributes:

Thus, to create a detail fetch group consisting of the publisher and articles relations, with the fetch group applied recursively to the related objects, use:

<fetch-group name="detail">
    <field name="publisher" fetch-depth="0"/>
    <field name="articles" fetch-depth="0"/>
</fetch-group>
[Note]Note

Kodo currently places the following restrictions on fetch groups:

  1. A given field may be in only one fetch group, including the default fetch group.

  2. All relation fields included in a custom fetch group must set their fetch-depth to 0, meaning the fetch group will be applied recursively to arbitrary depth.

The behavior mandated by these restrictions mimics the behavior of previous Kodo versions.

 

Skip navigation bar   Back to Top