Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.5
  Go To Table Of Contents
 Search
 PDFComments
Comments


@FetchAttribute

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

name

(Required) Name of the fetch attribute.




Usage

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.


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: