The JPA-defined jakarta. enumerates the
possibilities for when an association might be fetched. This
annotation defines how it is fetched in terms of the actual
SQL executed by the database.
Fetch, FetchProfile.FetchOverride#mode()
| Modifier and Type | Field and Description |
|---|---|
| public static final FetchMode | JOIN
Use an outer join to load all instances of the related entity or collection at once, as part of the execution of a query. |
| public static final FetchMode | SELECT
Use a secondary select to load a single associated entity or collection, at some point after an initial query is executed. |
| public static final FetchMode | SUBSELECT
Use a secondary select with a subselect that re-executes an initial query to load all instances of the related entity or collection at once, at some point after the initial query is executed. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public FetchMode | |
| public static FetchMode | |
| public static FetchMode[] |
| JOIN | back to summary |
|---|---|
| public static final FetchMode JOIN Use an outer join to load all instances of the related entity or collection at once, as part of the execution of a query. No subsequent queries are executed. This is the default fetching strategy for an association or collection that is explicitly marked for eager fetching. This fetching strategy is incompatible with lazy fetching since the associated data is retrieved as part of the initial query. | |
| SELECT | back to summary |
|---|---|
| public static final FetchMode SELECT Use a secondary select to load a single associated entity or collection, at some point after an initial query is executed. This is the default fetching strategy for any association or collection in Hibernate, unless the association or collection is explicitly marked for eager fetching. This fetching strategy is vulnerable to the "N+1 selects" bugbear, though the impact may be alleviated somewhat via:
This fetching strategy is, in principle, compatible with both
eager and
lazy fetching.
On the other hand, performance considerations dictate that it
should only be used in combination wih | |
| SUBSELECT | back to summary |
|---|---|
| public static final FetchMode SUBSELECT Use a secondary select with a subselect that re-executes an initial query to load all instances of the related entity or collection at once, at some point after the initial query is executed. This fetching strategy is currently only available for collections and many-valued associations. This advanced fetching strategy is compatible with both eager and lazy fetching. Subselect fetching may be contrasted with batch fetching:
| |
| FetchMode | back to summary |
|---|---|
| private FetchMode() | |
| getHibernateFetchMode | back to summary |
|---|---|
| public FetchMode getHibernateFetchMode() | |
| valueOf | back to summary |
|---|---|
| public static FetchMode valueOf(String name) | |
| values | back to summary |
|---|---|
| public static FetchMode[] values() | |