For example, consider a Customer entity has a Set of Orders. Each Order has a Set of OrderItems.
I can do this with named attributes:
EntityGraph<Customer> eg = em.createEntityGraph(Customer.class);
Subgraph<Order> egChild = eg.addSubgraph("orders");
egChild.addAttributeNodes("orderItems");
If I was only interested in Orders, I can do this using the metamodel:
EntityGraph<Customer> eg = em.createEntityGraph(Customer.class);
eg.addSubgraph(Customer_.orders);
But, If I want the entire graph using only the metamodel, I can not do this:
EntityGraph<Customer> eg = em.createEntityGraph(Customer.class);
Subgraph<Set<Order>> egChild = eg.addSubgraph(Customer_.orders);
egChild.addAttributeNodes(Order_.orderItems);
The problem seems to be that
eg.addSubgraph(Customer_.orders)
returns a
Subgraph<Set<Order>>
and not a
Subgraph<Order>
Is this a shortcoming of metamodel/entitygraphs, or am I missing something?