Eager subsequent-select fails when EntityGraph is specified for find operation

Description

IllegalArgumentException is thrown during two phase load's plan creation for member relation (i.e. ManyToMany).

While resolving relation, MetamodelGraphWalker visits each attribute of target entity type and checks whether fetchgraph or loadgraph has directed to eagerly fetch that attribute. If so, it modifies load plan.

Recent changes in 5.4.0 uses contracts specified by JPA 2.0 to walk down and manage types. getAttribute(name) contract specified by JPA's ManagedType throws IllegalArgumentException when asked attribute named as 'name' is not found.

But as per Hibernate's implementation, this contract is being used to check and modify load plan if attribute matches with specified EntityGraph.

In attached test case,
1) Defect class is loaded with fetch graph to load comments as well.
2) Hibernate successfully fires left join query on both tables and Result set is transformed to Entities
3) During initialization, Hibernate encounters User type in path
4) Hibernate start generating load plan for User type using internalLoad and encounter that entitygraph (specified for 'Defect' Type) is defined for this query
5) "User" type is walked down by MetamodelWalker to figure out matching fields with EntityGraph
6) No match is found (obviously because EntityGraph specified was written for "Defect" type, not "User" type)
7) Recent changes marks this situation as exceptional.

Environment

None

Assignee

Steve Ebersole

Reporter

Harsh Panchal

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Worked in

5.3.7

Components

Affects versions

Priority

Major
Configure