Annotation Interface Fetch
@Target({FIELD,METHOD})
@Retention(RUNTIME)
@Repeatable(Fetch.Fetches.class)
public @interface Fetch
Specifies options influencing how an attribute is fetched.
At most one such
- By default, the options apply when not overridden by
an entity graph. For a load
graph, options specified via the
@Fetchannotation are overridden when the graph has an attribute node representing the annotated attribute. For a fetch graph, options specified by@Fetchare always considered overridden. - When a graph name is specified, the options apply when the attribute is fetched using the named entity graph with the specified name and the named graph contains an attribute node representing the annotated attribute.
In this example, the @Fetch annotation is equivalent
to having specified @ManyToMany(fetch=EAGER):
@Fetch
@ManyToMany
List<Author> authors;
In this example, additional options influencing the mechanics of fetching the associated entity are specified:
@Fetch(cacheStoreMode=BYPASS, batchSize = 10)
@ManyToMany
List<Author> authors;
In this example, the options only apply when the named entity
graph BooksWithAuthors is used:
@Fetch(cacheStoreMode=BYPASS, batchSize = 10,
graph = "BooksWithAuthors")
@ManyToMany
List<Author> authors;
Multiple @Fetch annotations may be specified for a
single attribute:
@Fetch // eager by default
@Fetch(cacheStoreMode=BYPASS, batchSize = 10,
graph = "BooksWithAuthors")
@ManyToMany
List<Author> authors;
@Fetch annotation may have a missing
graph() name.- Since:
- 4.0
- See Also:
-
Nested Class Summary
Nested Classes -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionintA batch size, that is, how many entities should be fetched in each request to the database.Specifies whether the persistence provider is permitted to read the associated entity data from the cache.Specifies whether the persistence provider should cache the associated entity after fetching it from the database.The name of an entity graph.Vendor-specific fetching hints.String[]The names of one or more entity graphs to be attached as subgraphs of the named entity graph to the attribute node representing the annotated association.The fetching policy.
-
Element Details
-
graph
String graphThe name of an entity graph.- If no entity graph name is specified, the specified fetching options apply when the attribute is fetched without the use of an entity graph.
- Otherwise, the specified fetching options apply when the attribute is fetched using the entity graph with the specified name. The named graph contains an attribute node representing the annotated attribute.
At most one
@Fetchannotation of a given field or property may have a missinggraphname.- Default:
""
-
subgraph
-
type
FetchType typeThe fetching policy. Overrides the value specified by thefetchmember of theBasic,OneToOne,ManyToOne,OneToMany,ManyToMany, orElementCollectionannotation.- Default:
EAGER
-
batchSize
int batchSizeA batch size, that is, how many entities should be fetched in each request to the database. This option is always a hint, and might be ignored by the persistence provider.- Default:
-1
-
cacheStoreMode
CacheStoreMode cacheStoreModeSpecifies whether the persistence provider should cache the associated entity after fetching it from the database.- Default:
USE
-
cacheRetrieveMode
CacheRetrieveMode cacheRetrieveModeSpecifies whether the persistence provider is permitted to read the associated entity data from the cache.- Default:
USE
-
hints
QueryHint[] hintsVendor-specific fetching hints.Any hint not recognized by a provider is ignored.
- Default:
{}
-