Skip Headers

# Configuring Default Fetch Group Behavior

Previous

Next

You can optionally designate at most one fetch group as the default fetch group for a descriptor's reference class.

If you execute a `ReadObjectQuery` or `ReadAllQuery` without specifying a fetch group, TopLink will use the default fetch group unless you configure the query otherwise, as Example: Configuring Default Fetch Group Behavior shows.

Configuring Default Fetch Group Behavior

    // at the descriptor level
    FetchGroup group = new FetchGroup("nameOnly");
    group.addAttribute("firstName");
    group.addAttribute("lastName");
    employeeDescriptor.getFetchGroupManager().addFetchGroup(group);
    // set the default fetch group
    employeeDescriptor.getFetchGroupManager().setDefaultFetchGroup(group);

    // when query1 is executed, the default fetch group applies
    ReadAllQuery query1 = new ReadAllQuery(Employee.class);

    // when query2 is executed, the default fetch group does not apply
    ReadAllQuery query2 = new ReadAllQuery(Employee.class);
    query2.setShouldUsedefaultFetchGroup(false);