Enum Class FetchType
- All Implemented Interfaces:
FetchOption, Serializable, Comparable<FetchType>, Constable
Defines policies for fetching data from the database.
- The
EAGERpolicy is a requirement on the persistence provider runtime that data must be eagerly fetched. - The
LAZYpolicy is a hint to the persistence provider runtime that data should be fetched lazily when it is first accessed, in the case of a managed entity associated with a persistence context, or on a call toEntityAgent.fetch(T), in the case of a detached entity. The implementation is permitted to eagerly fetch data for which theLAZYpolicy hint has been specified. - A
DEFAULTvalue specifies that the fetching policy depends on the default fetch type of the persistence unit for one-to-one and many-to-one associations. This default fetch type is controlled via thedefault-to-one-fetch-typeelement in thepersistence.xmlfile or by setting thedefaultToOneFetchTypeof thePersistenceConfiguration, and defaults toEAGERfor backward compatibility.
This example specifies that a ManyToOne association
should, by default, be fetched lazily on first access:
@ManyToOne(fetch = LAZY)
private Publisher publisher;
This example specifies that an ElementCollection is
fetched eagerly:
@ElementCollection(fetch = EAGER)
Set<String> topics;
The use of fetch = EAGER often leads to fetching of
unwanted data and is therefore discouraged. Eager fetching
may be explicitly requested precisely where needed using an
EntityGraph or a query with left join fetch.
- Since:
- 1.0
- See Also:
- API note:
- It is very strongly recommended that new applications
set the default fetch type for one-to-one
and many-to-one associations to
LAZYto avoid accidental fetching of unnecessary data.
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Method Summary
-
Enum Constant Details
-
LAZY
Specifies that data can be lazily fetched.This fetching policy is a hint to the provider. A persistence provider is always permitted to eagerly fetch more data than what is explicitly requested by the application.
-
EAGER
Specifies that data must be eagerly fetched.This fetching policy is a requirement on the persistence provider.
-
DEFAULT
Specifies that the fetching policy depends on the default fetch type of the persistence unit for one-to-one and many-to-one associations.- Since:
- 4.0
- API note:
- It is very strongly recommended that
new applications set the default fetch type to
LAZYto avoid accidental fetching of unnecessary data.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-