To specify entity graphs for both typed and untyped queries, call the setHint
method on the query object and specify either javax.persistence.loadgraph
or javax.persistence.fetchgraph
as the property name and an EntityGraph
instance as the value:
EntityGraph<EmailMessage> eg = em.getEntityGraph("previewEmailEntityGraph"); List<EmailMessage> messages = em.createNamedQuery("findAllEmailMessages") .setParameter("mailbox", "inbox") .setHint("javax.persistence.loadgraph", eg) .getResultList();
In this example, the previewEmailEntityGraph
is used for the findAllEmailMessages
named query.
Typed queries use the same technique:
EntityGraph<EmailMessage> eg = em.getEntityGraph("previewEmailEntityGraph"); CriteriaQuery<EmailMessage> cq = cb.createQuery(EmailMessage.class); Root<EmailMessage> message = cq.from(EmailMessage.class); TypedQuery<EmailMessage> q = em.createQuery(cq); q.setHint("javax.persistence.loadgraph", eg); List<EmailMessage> messages = q.getResultList();
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3