Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Advanced JPA Development/Performance/Fetch Groups"

m
m (Fetch Groups (Advanced))
Line 1: Line 1:
 
=Fetch Groups (Advanced)=
 
=Fetch Groups (Advanced)=
 +
By default, when you execute an object-level read query for a particular object class, EclipseLink returns all the persistent attributes mapped in the object's descriptor. With this single query, all the object's persistent attributes are defined, and calling their <tt>get</tt> methods returns the value directly from the object.
  
 +
When you are interested in only some of the attributes of an object, it may be more efficient to return only a subset of the object's attributes using a fetch group.
 +
 +
Using a fetch group, you can define a subset of an object's attributes and associate the fetch group with either a <tt>ReadObjectQuery</tt> or <tt>ReadAllQuery</tt> query. When you execute the query, EclipseLink retrieves only the attributes in the fetch group. EclipseLink automatically executes a query to fetch all the attributes excluded from this subset when and if you call a <tt>get</tt> method on any one of the excluded attributes.
 +
 +
You can define more than one fetch group for a class. You can optionally designate at most one such fetch group as the default fetch group. If you execute either a <tt>ReadObjectQuery</tt> or <tt>ReadAllQuery</tt> query without specifying a fetch group, EclipseLink will use the default fetch group, unless you configure the query otherwise (see [[Using%20Advanced%20Query%20API%20(ELUG)#How to Configure Default Fetch Group Behavior|How to Configure Default Fetch Group Behavior]]).
 +
 +
You can use fetch groups in JPA projects for EJB objects, as well as for POJO classes. For POJO classes, use partial object querying (see [[Introduction%20to%20EclipseLink%20Queries%20(ELUG)#Partial Object Queries|Partial Object Queries]]).
 +
 +
Before using fetch groups, we recommend that you perform a careful analysis of system use. In many cases, the extra queries required to load attributes not in the fetch group could well offset the gain from the partial attribute loading. For more information about optimizing read performance, see [[Optimizing%20the%20EclipseLink%20Application%20(ELUG)#Read Optimization Examples|Read Optimization Examples]].
  
  

Revision as of 12:25, 16 June 2010

Fetch Groups (Advanced)

By default, when you execute an object-level read query for a particular object class, EclipseLink returns all the persistent attributes mapped in the object's descriptor. With this single query, all the object's persistent attributes are defined, and calling their get methods returns the value directly from the object.

When you are interested in only some of the attributes of an object, it may be more efficient to return only a subset of the object's attributes using a fetch group.

Using a fetch group, you can define a subset of an object's attributes and associate the fetch group with either a ReadObjectQuery or ReadAllQuery query. When you execute the query, EclipseLink retrieves only the attributes in the fetch group. EclipseLink automatically executes a query to fetch all the attributes excluded from this subset when and if you call a get method on any one of the excluded attributes.

You can define more than one fetch group for a class. You can optionally designate at most one such fetch group as the default fetch group. If you execute either a ReadObjectQuery or ReadAllQuery query without specifying a fetch group, EclipseLink will use the default fetch group, unless you configure the query otherwise (see How to Configure Default Fetch Group Behavior).

You can use fetch groups in JPA projects for EJB objects, as well as for POJO classes. For POJO classes, use partial object querying (see Partial Object Queries).

Before using fetch groups, we recommend that you perform a careful analysis of system use. In many cases, the extra queries required to load attributes not in the fetch group could well offset the gain from the partial attribute loading. For more information about optimizing read performance, see Read Optimization Examples.


Eclipselink-logo.gif
Version: DRAFT
Other versions...

Back to the top