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:
FetchGroupManager#getDefaultFetchGroup() is created and stored
on the FetchGroupManager during metadata processing if any of the
basic (DirectToFieldMapping) are configured to be loaded directly.
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 the
FetchGroupManager#addFetchGroup(FetchGroup). Adding named groups in
code is typically done in a org.eclipse.persistence.config.DescriptorCustomizer and should be done
before the session is initialized at login. To use a named FetchGroup on a
query the native ObjectLevelReadQuery#setFetchGroupName(String) can
be used of for JPA users the org.eclipse.persistence.config.QueryHints#FETCH_GROUP_NAME an be used.
ObjectLevelReadQuery#setFetchGroup(FetchGroup) while JPA users
generally use the org.eclipse.persistence.config.QueryHints#FETCH_GROUP .
When a query is executed only one FetchGroup will be used. The order of precedence is:
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.
FetchGroupManager, QueryHints.FETCH_GROUP , LoadGroup
| Modifier and Type | Field and Description |
|---|---|
| protected EntityFetchGroup | entityFetchGroup
Caches the EntityFetch group for this FetchGroup |
| protected FetchGroupTracker | rootEntity
Stores a reference to the root entity for an Aggregate Object relationship. |
| private boolean | shouldLoad
Indicates whether this group should be also used as a |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addAttribute(String
A simple attribute, array or attributes forming a path attributeNameOrPath, CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>> - an AttributeGroup to be added. group)Overrides org. |
| public void | addAttribute(String
A simple attribute, array or attributes forming a path attributeNameOrPath, Collection<? extends CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>>> - a collection of AttributeGroups to be added. groups)Overrides org. |
| public void | addAttributeKey(String
A simple attribute, array or attributes forming a path to a
Map key attributeNameOrPath, CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>> - an AttributeGroup to be added. group)Overrides org. |
| public FetchGroup | clone()
Overrides org. |
| public EntityFetchGroup | Returns: the entityFetchGroupINTERNAL: Used to retrieve the EntityFetchGroup for this FetchGroup |
| public FetchGroup | getGroup(String attributeNameOrPath)
Overrides org. |
| public FetchGroupTracker | |
| public boolean | |
| public boolean | |
| protected FetchGroup | newGroup(String name, CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>> parent)
Overrides org. |
| public String | onUnfetchedAttribute(FetchGroupTracker entity, String attributeName)
INTERNAL: Called on attempt to get value of an attribute that hasn't been fetched yet. |
| public String | onUnfetchedAttributeForSet(FetchGroupTracker entity, String attributeName)
INTERNAL: Called on attempt to assign value to an attribute that hasn't been fetched yet. |
| public void | |
| public void | setShouldLoad(boolean shouldLoad)
Configure this group to also act as a |
| public void | setShouldLoadAll(boolean shouldLoad)
Configure this group to also act as a |
| protected void | |
| public boolean | Returns: true if this group will be used as aLoadGroupwhen
processing the results of a query to force the specified
relationships to be loaded.
|
| public LoadGroup | toLoadGroup(Map<AttributeGroup, LoadGroup> cloneMap, boolean loadOnly)
Overrides org. |
| public LoadGroup |
| entityFetchGroup | back to summary |
|---|---|
| protected EntityFetchGroup entityFetchGroup Caches the EntityFetch group for this FetchGroup | |
| rootEntity | back to summary |
|---|---|
| protected FetchGroupTracker rootEntity Stores a reference to the root entity for an Aggregate Object relationship. This ensures that partially loaded aggregates can be triggered. | |
| shouldLoad | back to summary |
|---|---|
| private boolean shouldLoad Indicates whether this group should be also used as a | |
| FetchGroup | back to summary |
|---|---|
| public FetchGroup() | |
| FetchGroup | back to summary |
|---|---|
| public FetchGroup(String name) | |
| addAttribute | back to summary |
|---|---|
| public void addAttribute(String attributeNameOrPath, CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>> group) Overrides org. Doc from org. 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:
| |
| addAttribute | back to summary |
|---|---|
| public void addAttribute(String attributeNameOrPath, Collection<? extends CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>>> groups) Overrides org. Doc from org. Add an attribute and the corresponding list of AttributeGroups. Multiple groups are added in the case of inheritance
| |
| addAttributeKey | back to summary |
|---|---|
| public void addAttributeKey(String attributeNameOrPath, CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>> group) Overrides org. Doc from org. 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:
| |
| clone | back to summary |
|---|---|
| public FetchGroup clone() Overrides org. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by
| |
| getEntityFetchGroup | back to summary |
|---|---|
| public EntityFetchGroup getEntityFetchGroup(FetchGroupManager fetchGroupManager) INTERNAL: Used to retrieve the EntityFetchGroup for this FetchGroup
| |
| getGroup | back to summary |
|---|---|
| public FetchGroup getGroup(String attributeNameOrPath) Overrides org. Returns FetchGroup corresponding to the passed (possibly nested) attribute.
| |
| getRootEntity | back to summary |
|---|---|
| public FetchGroupTracker getRootEntity() INTERNAL:
| |
| isEntityFetchGroup | back to summary |
|---|---|
| public boolean isEntityFetchGroup() | |
| isFetchGroup | back to summary |
|---|---|
| public boolean isFetchGroup() Overrides org.
| |
| newGroup | back to summary |
|---|---|
| protected FetchGroup newGroup(String name, CoreAttributeGroup<ATTRIBUTE_ITEM extends CoreAttributeItem, DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>> parent) Overrides org. Doc from org. Subclass may create different types.
| |
| onUnfetchedAttribute | back to summary |
|---|---|
| public String onUnfetchedAttribute(FetchGroupTracker entity, String attributeName) 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 | |
| onUnfetchedAttributeForSet | back to summary |
|---|---|
| public String onUnfetchedAttributeForSet(FetchGroupTracker entity, String attributeName) 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 | |
| setRootEntity | back to summary |
|---|---|
| public void setRootEntity(FetchGroupTracker rootEntity) INTERNAL:
| |
| setShouldLoad | back to summary |
|---|---|
| public void setShouldLoad(boolean shouldLoad) Configure this group to also act as a | |
| setShouldLoadAll | back to summary |
|---|---|
| public void setShouldLoadAll(boolean shouldLoad) Configure this group to also act as a | |
| setSubclassShouldLoad | back to summary |
|---|---|
| protected void setSubclassShouldLoad(boolean shouldLoad) passes should load to subclasses. | |
| shouldLoad | back to summary |
|---|---|
public boolean shouldLoad()
| |
| toLoadGroup | back to summary |
|---|---|
| public LoadGroup toLoadGroup(Map<AttributeGroup, LoadGroup> cloneMap, boolean loadOnly) Overrides org.
| |
| toLoadGroupLoadOnly | back to summary |
|---|---|
| public LoadGroup toLoadGroupLoadOnly() | |