Skip Headers

# Using Java

Previous

Next

To configure a fetch group, use a descriptor amendment method (see "Configuring Amendment Methods") as Example: Configuring a Fetch Group shows.

Configuring a Fetch Group

    //Create a FetchGroupManager for the descriptor
    descriptor.setFetchGroupManager(new FetchGroupManager());
    // Create a FetchGroup
    FetchGroup group = new FetchGroup("nameOnly");
    // Add attributes to FetchGroup. Alternatively, use
    // FetchGroup method addAttributes, passing in a Set of String attribute names
    group.addAttribute("firstName");
    group.addAttribute("lastName");
    // Add the FetchGroup to the FetchGroupManager
    descriptor.getFetchGroupManager().addFetchGroup(group);
    //Set the default fetch group
    descriptor.getFetchGroupManager().setDefaultFetchGroup(group);

Each instance of `FetchGroup` that you store in a descriptor must be configured with a fetch group name that is unique for that descriptor (that is, each descriptor owns a set of named fetch groups).

When configuring fetch groups, note that the primary key fields and other required fields (such as inheritance type and optimistic lock version) are always included in all fetch groups.Fetch groups can include direct and relationship attributes. Including a relationship attribute in a fetch group does not cause the relationship to be joined or instantiated: joining and indirection are set independently of fetch groups.

After you add a fetch group to a descriptor, you can configure a `ReadObjectQuery` or `ReadAllQuery` query with this fetch group by name (`nameOnly`) or rely on TopLink to use this fetch group by default. For more information, see "Using Queries With Fetch Groups".