| The above versions of Hibernate miss subclass subgraph support in the EntityGraph API. The EntityGraph API (http://docs.oracle.com/javaee/7/api/javax/persistence/EntityGraph.html) offers some functions to support subclass subgraphs, the two basic ones being:
- addSubclassSubgraph(Class): creates the subgraph to be used when the entitygraph's entity is of the given subtype, and
- addSubgraph(String, Class): creates the subgraph to be used when the given attribute of the entitygraph's entity is of the given subtype.
Even though the subclass subgraph support works fine for annotation-declared EntityGraphs (i.e., using @NamedEntityGraph, @NamedAttributeNode, and @NamedSubgraph), it doesn't work in the EntityGraph API. More specifically:
- Hibernate's implementation for EntityGraph#addSubclassSubgraph(Class) throws a NotYetImplementedException(), and
- Hibernate's implementation for EntityGraph#addSubgraph(String, Class) delegates to AttributeNodeImpl#isTreatableAs(EntityPersister,Class), which only returns true if the given subtype is a supertype of the attribute's type that was declared in the entity. Since a subtype of the attribute's type (as expected by the EntityGraph API) is never a supertype of the attribute's type, addSubgraph(String,Class) is unusable.
|