Class FetchGroup
- All Implemented Interfaces:
Serializable
,Cloneable
FetchGroup usage is only possible when an entity class implements the
FetchGroupTracker
interface so that the FetchGroup can be stored in
the entity. The entity must also use the provided check methods to ensure the
attributes are loaded prior to use. In general this support is enabled
through weaving of the entity classes. If an entity class does not implement
FetchGroupTracker
no FetchGroup functionality will be supported and
attempted use of a FetchGroup in a query will not result in the expected
behavior.
FetchGroups are defined in 3 ways:
- A
FetchGroupManager.getDefaultFetchGroup()
is created and stored on theFetchGroupManager
during metadata processing if any of the basic (DirectToFieldMapping
) are configured to be loaded directly. - A named FetchGroup can be defined and added to the
FetchGroupManager
. For JPA users this can be accomplished using annotation (@FetchGroup) or in an eclipselink-orm.xml. For JPA and native users named groups can be defined in code and added to theFetchGroupManager.addFetchGroup(FetchGroup)
. Adding named groups in code is typically done in aDescriptorCustomizer
and should be done before the session is initialized at login. To use a named FetchGroup on a query the nativeObjectLevelReadQuery.setFetchGroupName(String)
can be used of for JPA users theQueryHints.FETCH_GROUP_NAME
an be used. - A dynamic FetchGroup can be created within the application and used on a
query. For native API usage this is done using
ObjectLevelReadQuery.setFetchGroup(FetchGroup)
while JPA users generally use theQueryHints.FETCH_GROUP
.
When a query is executed only one FetchGroup will be used. The order of precedence is:
- If a FetchGroup is specified on a query it will be used.
- If no FetchGroup is specified but a FetchGroup name is specified and the FetchGroupManager has a group by this name it will be used.
- If neither a FetchGroup nor a FetchGroup name is specified on the query an the FetchGroupManager has a default group then it will be used.
- If none of these conditions are met then no FetchGroup will be used when executing a query.
Note: This includes the execution of queries to populate lazy and eager relationships.
Loading: A FetchGroup can optionally specify that it needs its
included relationships loaded. This can be done using
setShouldLoad(boolean)
and setShouldLoadAll(boolean)
as
well as the corresponding configurations in the @FetchGroup annotation and
the <fetch-group> element in the eclipselink-orm.xml. When this
is configured the FetchGroup will also function as a LoadGroup
causing all of its specified relationships to be populated prior to returning
the results from the query execution.
- See Also:
- Author:
- King Wang, dclarke, ailitchev
-
Field Summary
Modifier and TypeFieldDescriptionprotected org.eclipse.persistence.internal.queries.EntityFetchGroup
Caches the EntityFetch group for this FetchGroupprotected FetchGroupTracker
Stores a reference to the root entity for an Aggregate Object relationship.Fields inherited from class org.eclipse.persistence.core.queries.CoreAttributeGroup
allsubclasses, isValidated, items, name, subClasses, superClassGroup, type, typeName
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(String attributeNameOrPath, Collection<? extends CoreAttributeGroup> groups) Add an attribute and the corresponding list of AttributeGroups.void
addAttribute
(String attributeNameOrPath, CoreAttributeGroup group) Add a basic attribute or nested attribute with each String representing an attribute on the path to what needs to be included in the AttributeGroup.void
addAttributeKey
(String attributeNameOrPath, CoreAttributeGroup group) Add a basic attribute or nested attribute with each String representing the key of an attribute of type Map on the path to what needs to be included in the AttributeGroup.clone()
org.eclipse.persistence.internal.queries.EntityFetchGroup
getEntityFetchGroup
(FetchGroupManager fetchGroupManager) INTERNAL: Used to retrieve the EntityFetchGroup for this FetchGroupReturns FetchGroup corresponding to the passed (possibly nested) attribute.INTERNAL:boolean
boolean
protected FetchGroup
newGroup
(String name, CoreAttributeGroup parent) Subclass may create different types.onUnfetchedAttribute
(FetchGroupTracker entity, String attributeName) INTERNAL: Called on attempt to get value of an attribute that hasn't been fetched yet.onUnfetchedAttributeForSet
(FetchGroupTracker entity, String attributeName) INTERNAL: Called on attempt to assign value to an attribute that hasn't been fetched yet.void
setRootEntity
(FetchGroupTracker rootEntity) INTERNAL:void
setShouldLoad
(boolean shouldLoad) Configure this group to also act as aLoadGroup
when set to true and load all of the specified relationships so that the entities returned from the query where this group was used have the requested relationships populated.void
setShouldLoadAll
(boolean shouldLoad) Configure this group to also act as aLoadGroup
the same assetShouldLoad(boolean)
.protected void
setSubclassShouldLoad
(boolean shouldLoad) passes should load to subclasses.boolean
toLoadGroup
(Map<AttributeGroup, LoadGroup> cloneMap, boolean loadOnly) Methods inherited from class org.eclipse.persistence.queries.AttributeGroup
addAttribute, findGroup, getItem, isConcurrent, isCopyGroup, isLoadGroup, isSupersetOf, newItem, newItem, toCopyGroup, toCopyGroup, toFetchGroup, toFetchGroup, toLoadGroup
Methods inherited from class org.eclipse.persistence.core.queries.CoreAttributeGroup
addAttribute, addAttributes, clone, containsAttribute, containsAttributeInternal, convert, convertClassNamesToClasses, equals, getAllItems, getAttributeNames, getItem, getItems, getName, getSubClassGroups, getType, getTypeName, hashCode, hasInheritance, hasItems, insertSubClass, isSupersetOf, isValidated, removeAttribute, setAllSubclasses, setAttributeNames, setName, toString, toStringAdditionalInfo, toStringItems, toStringPath
-
Field Details
-
entityFetchGroup
protected org.eclipse.persistence.internal.queries.EntityFetchGroup entityFetchGroupCaches the EntityFetch group for this FetchGroup -
rootEntity
Stores a reference to the root entity for an Aggregate Object relationship. This ensures that partially loaded aggregates can be triggered.
-
-
Constructor Details
-
FetchGroup
public FetchGroup() -
FetchGroup
-
-
Method Details
-
onUnfetchedAttribute
INTERNAL: Called on attempt to get value of an attribute that hasn't been fetched yet. Returns an error message in case jakarta.persistence.EntityNotFoundException should be thrown by the calling method, null otherwise.This method is typically only invoked through woven code in the persistence object introduced when
FetchGroupTracker
is woven into the entity. -
onUnfetchedAttributeForSet
INTERNAL: Called on attempt to assign value to an attribute that hasn't been fetched yet. Returns an error message in case jakarta.persistence.EntityNotFoundException should be thrown by the calling method, null otherwise.This method is typically only invoked through woven code in the persistence object introduced when
FetchGroupTracker
is woven into the entity. -
getRootEntity
INTERNAL:- Returns:
- the rootEntity
-
setRootEntity
INTERNAL:- Parameters:
rootEntity
- the rootEntity to set
-
setShouldLoad
public void setShouldLoad(boolean shouldLoad) Configure this group to also act as aLoadGroup
when set to true and load all of the specified relationships so that the entities returned from the query where this group was used have the requested relationships populated. All subsequent attributes added to this group that create a nested group will have this value applied to them. -
setSubclassShouldLoad
protected void setSubclassShouldLoad(boolean shouldLoad) passes should load to subclasses. -
setShouldLoadAll
public void setShouldLoadAll(boolean shouldLoad) Configure this group to also act as aLoadGroup
the same assetShouldLoad(boolean)
. Additionally this method will apply the provided boolean value to all nested groups already added. -
shouldLoad
public boolean shouldLoad()- Returns:
- true if this group will be used as a
LoadGroup
when processing the results of a query to force the specified relationships to be loaded.
-
newGroup
Description copied from class:AttributeGroup
Subclass may create different types.- Overrides:
newGroup
in classAttributeGroup
-
isFetchGroup
public boolean isFetchGroup()- Overrides:
isFetchGroup
in classCoreAttributeGroup<org.eclipse.persistence.internal.queries.AttributeItem,
ClassDescriptor>
-
isEntityFetchGroup
public boolean isEntityFetchGroup() -
toLoadGroupLoadOnly
-
clone
- Overrides:
clone
in classAttributeGroup
-
toLoadGroup
- Overrides:
toLoadGroup
in classAttributeGroup
-
getEntityFetchGroup
public org.eclipse.persistence.internal.queries.EntityFetchGroup getEntityFetchGroup(FetchGroupManager fetchGroupManager) INTERNAL: Used to retrieve the EntityFetchGroup for this FetchGroup- Returns:
- the entityFetchGroup
-
getGroup
Returns FetchGroup corresponding to the passed (possibly nested) attribute.- Overrides:
getGroup
in classAttributeGroup
-
addAttribute
Description copied from class:CoreAttributeGroup
Add a basic attribute or nested attribute with each String representing an attribute on the path to what needs to be included in the AttributeGroup.Example:
group.addAttribute("firstName", group1);
Note that existing group corresponding to attributeNameOrPath will be overridden with the passed group.
group.addAttribute("manager.address", group2);- Overrides:
addAttribute
in classCoreAttributeGroup<org.eclipse.persistence.internal.queries.AttributeItem,
ClassDescriptor> - Parameters:
attributeNameOrPath
- A simple attribute, array or attributes forming a pathgroup
- - an AttributeGroup to be added.
-
addAttribute
public void addAttribute(String attributeNameOrPath, Collection<? extends CoreAttributeGroup> groups) Description copied from class:CoreAttributeGroup
Add an attribute and the corresponding list of AttributeGroups. Multiple groups are added in the case of inheritance- Overrides:
addAttribute
in classCoreAttributeGroup<org.eclipse.persistence.internal.queries.AttributeItem,
ClassDescriptor> - Parameters:
attributeNameOrPath
- A simple attribute, array or attributes forming a pathgroups
- - a collection of AttributeGroups to be added.
-
addAttributeKey
Description copied from class:CoreAttributeGroup
Add a basic attribute or nested attribute with each String representing the key of an attribute of type Map on the path to what needs to be included in the AttributeGroup.Example:
group.addAttribute("firstName", group1);
Note that existing group corresponding to attributeNameOrPath will be overridden with the passed group.
group.addAttribute("manager.address", group2);- Overrides:
addAttributeKey
in classCoreAttributeGroup<org.eclipse.persistence.internal.queries.AttributeItem,
ClassDescriptor> - Parameters:
attributeNameOrPath
- A simple attribute, array or attributes forming a path to a Map keygroup
- - an AttributeGroup to be added.
-