Top Description Inners Methods
org.hibernate.annotations

public @Interface FetchProfile

extends Annotation
Annotations
@Target:TYPE, PACKAGE
@Retention:RUNTIME
@Repeatable:FetchProfiles
Imports
jakarta.persistence.FetchType, java.lang.annotation.Repeatable, .Retention, .Target

Defines a fetch profile, by specifying its name, together with a list of fetch strategy overrides. The definition of a single named fetch profile may be split over multiple @FetchProfile annotations which share the same name.

Additional fetch strategy overrides may be added to a named fetch profile by annotating the fetched associations themselves with the @FetchProfileOverride annotation, specifying the name of the fetch profile.

A named fetch profile must be explicitly enabled in a given session by calling org.hibernate.Session#enableFetchProfile(String) for it to have any effect at runtime.

Fetch profiles compete with JPA-defined named entity graphs, and so programs which wish to maintain compatibility with alternative implementations of JPA should prefer @NamedEntityGraph. The semantics of these two facilities are not quite identical, however, since a fetch profile is a list, not a graph.

Or, if we insist on thinking in terms of graphs:

However, a fetch profile is not by nature rooted at any one particular entity, and so @FetchProfile is not required to annotate the entity classes it affects. It may even occur as a package-level annotation.

Instead, the root entity of a fetch graph is determined by the context in which the fetch profile is active. For example, if a fetch profile is active when org.hibernate.Session#get(Class, Object) is called, then the root entity is the entity with the given Class. Given a root entity as input, an active fetch profile contributes to the determination of the fetch graph.

A JPA jakarta.persistence.EntityGraph may be constructed in Java code at runtime. But this amounts to a separate, albeit extremely limited, query facility that competes with JPA's own criteria queries. There's no such capability for fetch profiles.

Author
Hardy Ferentschik
See Also
FetchProfileOverride, org.hibernate.Session#enableFetchProfile(String), org.hibernate.SessionFactory#containsFetchProfileDefinition(String)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static @interface
FetchProfile.FetchOverride

Overrides the fetching strategy for a particular association in the named fetch profile being defined.

Method Summary

Modifier and TypeMethod and Description
public FetchProfile.FetchOverride[]
fetchOverrides()

The list of association fetching strategy overrides.

public String
name()

The name of the fetch profile.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

fetchOverridesback to summary
public FetchProfile.FetchOverride[] fetchOverrides()

The list of association fetching strategy overrides.

Additional overrides may be specified by marking the fetched associations themselves with the @Fetch annotation.

nameback to summary
public String name()

The name of the fetch profile. Must be unique within a persistence unit.

See Also
org.hibernate.SessionFactory#getDefinedFetchProfileNames()
org.hibernate.annotations back to summary

public @Interface FetchProfile.FetchOverride

extends Annotation
Annotations
@Target:TYPE, PACKAGE
@Retention:RUNTIME

Overrides the fetching strategy for a particular association in the named fetch profile being defined. A "strategy" is a fetching method, together with the timing. If mode and fetch are both unspecified, the strategy defaults to eager join fetching.

Additional fetch strategy overrides may be specified using the @FetchProfileOverride annotation.

See Also
FetchProfileOverride

Method Summary

Modifier and TypeMethod and Description
public String
association()

The association whose default fetch strategy is being overridden.

public Class<?>
entity()

The entity containing the association whose default fetch strategy is being overridden.

public FetchType
fetch()

The timing of association fetching in the fetch profile being defined.

public FetchMode
mode()

The method used for fetching the association in the fetch profile being defined.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

associationback to summary
public String association()

The association whose default fetch strategy is being overridden.

entityback to summary
public Class<?> entity()

The entity containing the association whose default fetch strategy is being overridden.

fetchback to summary
public FetchType fetch()

The timing of association fetching in the fetch profile being defined.

modeback to summary
public FetchMode mode()

The method used for fetching the association in the fetch profile being defined.