Java Reference
In-Depth Information
@JoinColumn(foreignKey = @ForeignKey(name =
"FK"))
private Student student;
//...
}
Entity graphs
When we talk about an entity graph, we have to keep in mind a data structure in-
volving several related entities. With the previous version of JPA, the efficient load-
ing of data of an entity was essentially managed through the fetch setting. The con-
sequence was that it was necessary to set the fetch attribute of some annotations
before compiling the application (or before deployment in the case of XML configur-
ation) in order to request that an entity attribute be loaded eagerly (when entity is
loaded) or lazily (when data is needed). Through entity graphs, you can now over-
ride or change the fetch setting at runtime.
An entity graph can be defined statically by using a vast NamedEntityGraph ,
NamedEntityGraphs , NamedSubgraph , and NamedAttributeNode annota-
tions, or dynamically through EntityGraph , subgraph , and AttributeNode in-
terfaces.
Static or named entity graphs
The @NamedEntityGraph annotation is used to define an entity graph that can be
used at runtime when executing queries or using the find() method. The follow-
ing code shows an example of the definition of a named entity graph with one field:
students .
@Entity
@NamedEntityGraph(name="includeThis",attributeNodes={@NamedAttributeNode("students")})
public class Department implements Serializable
{
private static final long serialVersionUID =
1L;
@Id
Search WWH ::




Custom Search