2

I am about to use new features from JPA 2.1. One of them is named entity graph.

If my entity has two graphs, can I use these in a query?

EntityGraph graph1 = this.em.getEntityGraph("graph.Order.items");
EntityGraph graph2 = this.em.getEntityGraph("graph.Order.address");

For exampe, like below

Map hints = new HashMap();
hints.put("javax.persistence.fetchgraph", graph1);
hints.put("javax.persistence.fetchgraph", graph2);

Order order = this.em.find(Order.class, orderId, hints);

or

entityManager.setHint("javax.persistence.fetchgraph", graph1);
entityManager.setHint("javax.persistence.fetchgraph", graph2);

The reason is that I other queries may need only one among defined graphs.

Chris
  • 199
  • 2
  • 13

1 Answers1

2

I've tested this.

If multiple graphs has been assigned, the last one will be applied.

Chris
  • 199
  • 2
  • 13
  • Do you know if there is a way to chain the graphs ? I am asking related to my question http://stackoverflow.com/questions/38505745/named-entity-graph-sub-subgraph – sashok_bg Aug 11 '16 at 12:04
  • 1
    This is because in map the keys should be unique. And you try to put two values for a single key. This is impossible. This is core java issue not an EntityGraph issue – Filosssof Dec 07 '17 at 09:36