Diamond shaped OneToMany + FetchType.EAGER + FetchMode.JOIN causes N+1 selects

Description

Problem summary:
When mapping "diamond shaped" OneToMany relationships using FetchType.EAGER and FetchMode.JOIN, Hibernate generates N+1 select statements. Here is what I mean with "diamond shape":

Expected behavior:
A single select statement with two joins on the "BOTTOM" table.

Actual behavior:

Detailed explanation and code sample:
https://stackoverflow.com/q/51199440/3216347

Test Case:
https://github.com/hibernate/hibernate-orm/pull/2402

Environment

None

Assignee

Unassigned

Reporter

Pit Humke

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure