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