Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.4
  Go To Table Of Contents


Use @FetchAttribute to improve performance within a fetch group; it allows on-demand loading of a group of an object's attributes. As a result, the data for an attribute might not be loaded from the datasource until an explicit access call occurs.

This avoids loading all the data of an object's attributes if the user requires only some of the attributes.

Annotation Elements

Table 2-21 describes this annotation's elements.

Table 2-21 @FetchAttribute Annotation Elements

Annotation Element Description Default


(Required) Name of the fetch attribute.


EclipseLink provides two types of fetch groups:

You should extensively review your use cases when using fetch groups. In many cases, additional round-trips will offset any gains from deferred loading.


Example 2-42 shows how to use @FetchAttribute within a @FetchGroup annotation.

Example 2-42 Using @FetchAttribute Annotation

@FetchGroup(name="basic-fetch-group", attributes={
public class Person {
   private int id;
   private String name;
   private Address address;
   private ContactInfo contactInfo;

Example 2-43 Using <fetch-group> XML

<fetch-group name="basic-fetch-group">
    <attribute name="id"/>
    <attribute name="name"/>
    <attribute name="address"/>

See Also

For more information, see: