Hibernate JPA @NamedEntityGraph Example

@NamedEntityGraph

The @NamedEntityGraph annotation is used to specify an Entity Graph that can be used by an entity query to override the default fetch plan. NamedEntityGraph Used to specify the path and boundaries for a find operation or query.

Fetch graph example

@Entity(name = "Employee")
@NamedEntityGraph(name = "employee.projects",
attributeNodes = @NamedAttributeNode("projects")
)
Employee employee = entityManager.find(
Employee.class,
userId,
Collections.singletonMap(
"javax.persistence.fetchgraph",
entityManager.getEntityGraph( "employee.projects" )
)
);

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations