JPA - (Association) Fetch

About

The fetch attribute is a enum that specifies whether to load the field's persisted data:

  • before the entity object is returned by the persistence provider (FetchType.EAGER)
  • or later, when the property is accessed (FetchType.LAZY).

The default behavior is:

  • to fetch one-to-one and many-to-one relationships eagerly (FetchType.EAGER)
  • and to fetch one-to-many and many-to-many relationships lazily (FetchType.LAZY)

In most cases, the default behavior is the most sensible approach.

Management

The PersistenceUtil.isLoaded methods can be used to determine the load state of an entity and its attributes regardless of the persistence unit with which the entity is associated.

Documentation / Reference

  • See 3.2.9 Load State from the specifications

Powered by ComboStrap