*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":
!Diamond.jpg|thumbnail!
*Expected behavior:* A single select statement with two joins on the "BOTTOM" table.
*Actual behavior:* {code:sql} SELECT top0_.id AS id1_3_0_, left1_.parent AS parent2_1_1_, left1_.id AS id1_1_1_, left1_.id AS id1_1_2_, left1_.parent AS parent2_1_2_, bottom2_.parent AS parent2_0_3_, bottom2_.id AS id1_0_3_, bottom2_.id AS id1_0_4_, bottom2_.parent AS parent2_0_4_, right3_.parent AS parent2_2_5_, right3_.id AS id1_2_5_, right3_.id AS id1_2_6_, right3_.parent AS parent2_2_6_ FROM Top top0_ LEFT OUTER JOIN Left left1_ ON top0_.id = left1_.parent LEFT OUTER JOIN Bottom bottom2_ ON left1_.id = bottom2_.parent LEFT OUTER JOIN Right right3_ ON top0_.id = right3_.parent WHERE top0_.id = ?
SELECT bottom0_.parent AS parent2_0_0_, bottom0_.id AS id1_0_0_, bottom0_.id AS id1_0_1_, bottom0_.parent AS parent2_0_1_ FROM Bottom bottom0_ WHERE bottom0_.parent = ? {code}
*Detailed explanation and code sample:* https://stackoverflow.com/q/51199440/3216347
*Test Case:* I am currently working on a test case https://github . I will update this ticket as soon as possible. com/hibernate/hibernate-orm/pull/2402 |
|