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. |
Usage
EclipseLink provides two types of fetch groups:
Pre-defined fetch groups at the Entity or MappedSuperclass level
Dynamic (use case) fetch groups at the query level
You should extensively review your use cases when using fetch groups. In many cases, additional round-trips will offset any gains from deferred loading.
Examples
Example 2-42 shows how to use @FetchAttribute
within a @FetchGroup
annotation.
Example 2-42 Using @FetchAttribute Annotation
@Entity @FetchGroup(name="basic-fetch-group", attributes={ @FetchAttribute(name="id"), @FetchAttribute(name="name"), @FetchAttribute(name="address")}) public class Person { @Id private int id; private String name; @OneToOne(fetch=LAZY) private Address address; @ManyToOne(fetch=EAGER) 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"/> </fetch-group>
See Also
For more information, see:
Understanding EclipseLink