Package org.hibernate.annotations
Annotation Interface LazyGroup
Specifies the fetch group for a persistent attribute of an entity
class. This annotation has no effect unless bytecode enhancement is used,
and field-level lazy fetching is enabled.
- When bytecode enhancement is not used, declaring a field as
@Basic(fetch=LAZY)
has no effect on the runtime behavior of Hibernate. All fields of an entity are loaded at the same time, as if they all belonged to the same fetch group. - But when bytecode enhancement is used, a field declared
@Basic(fetch=LAZY)
} is loaded lazily when it is first accessed, using a separate SQLselect
statement. Since this trip to the database is generally expensive, Hibernate will, by default, load all lazy fields at once. This annotation provides control over that behavior.
A fetch group identifies a set of related attributes that should be loaded
together when any one of them is accessed. By default, all non-collection
attributes belong to a single fetch group named "DEFAULT"
. The
fetch group for a given lazy attribute may be explicitly specified using
the value()
member of this annotation.
For example, a field annotated @Basic(fetch=LAZY) @LazyGroup("extra")
belongs to the fetch group named "extra"
, and is loaded whenever an
attribute belonging to the "extra"
fetch group is accessed.
Note that field-level lazy fetching is usually of dubious value, and most projects using Hibernate don't even bother enabling the bytecode enhancer.
- See Also:
-
Required Element Summary
Required Elements
-
Element Details
-
value
String value
-