Java Reference
In-Depth Information
@Basic(optional = false)
private String id;
private String name;
private Integer nbrlevel;
private String phone;
@OneToMany(mappedBy = "depart",fetch =
private List<Student> students;
/*getter and setter*/
Once defined, we need to retrieve our named entity graph using the
getEntityGraph() method of EntityManager in order to use it as a property
when searching with the find method or as a query hint with a query. After executing
the following code, you will notice that in the first search, the students attribute will
not be loaded while in the second search it will be.
The following code is an example of using a named entity graph:
EntityManager em = emf.createEntityManager();
//create entity manager
PersistenceUnitUtil pUtil =
Department depart = (Department)
em.createQuery("Select e from Department e")
System.out.println("students Was loaded ?
"+pUtil.isLoaded(depart, "students"));
EntityGraph includeThis =
depart = (Department) em.createQuery("Select e
from Department e")
Search WWH ::

Custom Search