As mentioned, thank you for your advice
为情所困2017-05-17 10:05:48
SUBSELECT: avoids N+1 and does not duplicate data, but loads all entities of related types into memory.
FetchMode.SUBSELECT should look like this:
SELECT <employees columns>
FROM EMPLOYEE employees0_
WHERE employees0_.DEPARTMENT_ID IN
(SELECT department0_.DEPARTMENT_ID FROM DEPARTMENT department0_)
FetchMode.SUBSELECT can significantly reduce the number of queries
I found a very good article