Annotation Interface EntityGraph


@Retention(RUNTIME) @Target({METHOD,ANNOTATION_TYPE}) @Documented public @interface EntityGraph
Configures the JPA entity graph used by a repository query method, which controls which associations are fetched together with the entity in the same query, overriding the fetch type declared on the mapping. Use it to load lazy associations eagerly for a particular query and avoid additional queries when they are accessed.

Either reference a named entity graph declared on the entity with @NamedEntityGraph using name(), or list the association paths to fetch with attributePaths() (for example "author" or "author.publisher"), in which case an entity graph is built at runtime. The graph is passed to the persistence provider as the query hint named by hint(): a fetch graph by default, which treats attributes not in the graph as lazy, or a load graph (jakarta.persistence.loadgraph), which keeps the mapped fetch type for them.

Similar to Spring Data JPA's @EntityGraph.

Since:
1.0.0
Author:
graemerocher
  • Element Details

    • value

      @AliasFor(member="name") String value
      Same as name().
      Returns:
      The name of the entity graph.
      Default:
      ""
    • name

      @AliasFor(member="value") String name
      Specifies the name of the entity graph. If none is specified one will be created at runtime.
      Returns:
      The name of the entity graph to use.
      Default:
      ""
    • hint

      String hint
      Returns:
      The name of the hint to use.
      See Also:
      Default:
      "jakarta.persistence.fetchgraph"
    • attributePaths

      String[] attributePaths
      The attributes paths to include in the entity graph.
      Returns:
      The attributes paths
      Default:
      {}