Hibernate HQL: use JOIN to actively load child objects?

I found this HQL query that I am trying to understand. The comment says that LEFT JOINmakes Hibernate eagerly load related objects into the child table, and a modifier is DISTINCTneeded to filter out duplicate parent objects in the result set. Do these comments make sense? I have not seen a connection used like this before.

SELECT DISTINCT p FROM Parent AS p
LEFT JOIN p.children AS c
WHERE p.state = 1
ORDER BY p.modified

Note is cnot used in sentences WHEREor ORDER BY.

It seems to be safe to replace this query with a simpler one:

SELECT p FROM Parent AS p
WHERE p.state = 1
ORDER BY p.modified

But I'm not sure if there is a good reason why the original request was written as is.

+3
1

Hibernate:

"fetch" ​​ . . .

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html

, "", . "", , .

, , .

+3

Source: https://habr.com/ru/post/1778846/


All Articles