Jump to: navigation, search

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

m
m (Fetch Groups)
(7 intermediate revisions by one other user not shown)
Line 3: Line 3:
 
|toc=n
 
|toc=n
 
|eclipselink=y
 
|eclipselink=y
|eclipselinktype=JPA}}
+
|eclipselinktype=JPA
=Fetch Groups (Advanced)=
+
|api=y
 +
|apis=
 +
*[[http://www.eclipse.org/eclipselink/api/2.2/org/eclipse/persistence/queries/FetchGroup.html FetchGroup]]
 +
|examples=y
 +
|example=
 +
*[[http://wiki.eclipse.org/EclipseLink/Examples/JPA/AttributeGroup Attribute Group]]}}
 +
=Fetch Groups=
 
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.
 
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.
  
Line 11: Line 17:
 
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.
 
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 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).
  
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]]).
+
You can use fetch groups in JPA projects for EJB objects, as well as for POJO classes. For POJO classes, use partial object querying).
  
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]].
+
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.
 +
 
 +
Fetch groups can be used only with basic mappings configured with FetchType.LAZY (partial object queries).
  
 
In the 2.1.0, EclipseLink introduces the '''[[EclipseLink/Examples/JPA/AttributeGroup|AttributeGroup]]''' that can be used configure the use of partial entities in fetch, load, copy, and merge operations.  
 
In the 2.1.0, EclipseLink introduces the '''[[EclipseLink/Examples/JPA/AttributeGroup|AttributeGroup]]''' that can be used configure the use of partial entities in fetch, load, copy, and merge operations.  
Line 22: Line 30:
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA
 
|previous=[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Disabling Weaving with Persistence Unit Properties|Disabling Weaving with Persistence Unit Properties]]
 
|previous=[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Disabling Weaving with Persistence Unit Properties|Disabling Weaving with Persistence Unit Properties]]
|next    =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Platform Specific Configurations|Platform Specific Configurations]]
+
|next    =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Attribute_Group|Attribute Groups]]
 
|up      =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance|Performance]]
 
|up      =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance|Performance]]
 
|version=2.2.0 DRAFT}}
 
|version=2.2.0 DRAFT}}

Revision as of 12:54, 13 October 2011

EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

Elug api package icon.png Key API

Elug example icon.png Examples

Fetch Groups

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).

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

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.

Fetch groups can be used only with basic mappings configured with FetchType.LAZY (partial object queries).

In the 2.1.0, EclipseLink introduces the AttributeGroup that can be used configure the use of partial entities in fetch, load, copy, and merge operations.


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