Java Reference
In-Depth Information
.getResultList().get(0);
System.out.println("students Was loaded ?
"+pUtil.isLoaded(depart,"students"));
Dynamic entity graphs
Entity graphs can also be defined at runtime. To do this, we must use the cre-
ateEntityGraph() method of the entity manager and not getEntityGraph()
as with the named entity graphs. Once defined, the dynamic entity graph is asso-
ciated with the find() method or a query in the same way as a named entity graph
as shown in the following code.
The following code is an example of using a dynamic entity graph:
EntityManager em = emf.createEntityManager();
//create entity manager
PersistenceUnitUtil pUtil =
emf.getPersistenceUnitUtil();
Department depart = (Department)
em.createQuery("Select e from Department e")
.getResultList().get(0);
System.out.println("students Was loaded ? " +
pUtil.isLoaded(depart, "students"));
EntityGraph includeThis =
em.createEntityGraph(Department.class);
includeThis.addAttributeNodes("students");
depart = (Department) em.createQuery("Select e
from Department e")
.setHint("javax.persistence.fetchgraph",
includeThis)
.getResultList().get(0);
System.out.println("students Was loaded ? "
+pUtil.isLoaded(depart, "students"));
Search WWH ::




Custom Search