| Redundant left outer joins generated in SQL query when HQL query contains left join on some entity (not by primary key). HQL: select c.inventoryNumber from Employee e left join Computer c on c.workplace = e.workplace Generated SQL:
And if there is join by primary key: select c.inventoryNumber from Employee e left join Computer c on c.workplace*.id* = e.workplace*.id* Then the generated SQL looks like:
No redundant joins here. The problem is that such SQL significantly impacts performance when selecting from several large tables. To reproduce you can run the following test and see the generated query in output: org.hibernate.bugs.QueryGenerationTestCase#testRedundantSqlJoins from https://github.com/stasal/hibernate-tests |