문제

What is this JPQL query?

SELECT e
FROM Department d JOIN d.employees e JOIN e.projects p
WHERE 
e.salary = :amount and 
d.name = :name and 
p.location = :location"

I understand the the first JOIN in which the Department gets joined by Employee entity but what's the reason for the second join while we are just selecting e?

도움이 되었습니까?

해결책

Joining to the projects of departments is necessary, because single project is later on needed in WHERE clause:

p.location = :location

Projects is a collection. Consequently e.projects is collection valued path expression. It is not possible navigate through collection valued path expression. Following construct is not expected to work, because collection does not have location property.

e.projects.location = :location
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top