jakartaee / persistence

https://jakartaee.github.io/persistence/
Other
191 stars 55 forks source link

EntityGraph and Subgraph need an addPluralSubgraph() operation #411

Closed gavinking closed 1 year ago

gavinking commented 1 year ago

The following code does not pass the typechecker:

var graph = em.createEntityGraph(Book.class);
graph.addSubgraph(Book_.publisher);
graph.addSubgraph(Book_.authors).addSubgraph(Author_.person);

So we need to add a method which lets us write:

var graph = em.createEntityGraph(Book.class);
graph.addSubgraph(Book_.publisher);
graph.addPluralSubgraph(Book_.authors).addSubgraph(Author_.person);

Its signature is:

<X> Subgraph<X> addPluralSubgraph(PluralAttribute<? extends T, ?, X> attribute)

and it needs to be declared on both EntityGraph and Subgraph.

I had never noticed this oversight before, but actually it's pretty bad if you're trying to use the typesafe API.

gavinking commented 1 year ago

Actually perhaps this should be called addElementSubgraph() to be more consistent with addKeySubgraph().