We're updating the issue view to help you get more done. 

Creating an entity sub graph on inherited attribute fails

Description

Having a mapped super class:

1 2 3 4 5 @MappedSuperclass public class MappedSupperclass { @OneToOne(fetch = FetchType.LAZY) public Bar bar; }

And extending class Foo:

1 2 3 @Entity public class Foo extends MappedSupperclass { }

Trying to add Subgraph:

1 2 EntityGraph<Foo> entityGraph = em.createEntityGraph( Foo.class ); entityGraph.addSubgraph( "bar" );

Throws exception:

1 2 3 4 5 6 7 8 9 10 org.hibernate.MappingException: Unknown entity: com.example.hibernate.bugs.inherited.MappedSupperclass at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:776) at org.hibernate.jpa.internal.metamodel.Helper.resolveAttributeSource(Helper.java:47) at org.hibernate.jpa.internal.metamodel.Helper.resolveType(Helper.java:96) at org.hibernate.jpa.graph.internal.AttributeNodeImpl.internalMakeSubgraph(AttributeNodeImpl.java:123) at org.hibernate.jpa.graph.internal.AttributeNodeImpl.makeSubgraph(AttributeNodeImpl.java:98) at org.hibernate.jpa.graph.internal.AbstractGraphNode.addSubgraph(AbstractGraphNode.java:159) at org.hibernate.jpa.graph.internal.EntityGraphImpl.addSubgraph(EntityGraphImpl.java:81) at org.hibernate.jpa.graph.internal.EntityGraphImpl.addSubgraph(EntityGraphImpl.java:26) at com.example.hibernate.bugs.inherited.InheritedEntityGraphTest.attributeNodeInheritanceTest(InheritedEntityGraphTest.java:71)

Reason:
In AttributeNodeImpl,internalMakeSubgraph the declaring type of the attribute is used not the queried managed type.

PR will follow

Environment

None

Status

Assignee

Unassigned

Reporter

Oliver Breidenbach

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

5.0.3

Priority

Critical