You can define multiple identifiers in the FROM clause, and you'll see how to use them
when we discuss joining multiple entities by association or field name later in this chapter.
What is a path expression?
In the JPQL example you used expressions such as c.categoryName and
c.categoryId . These are known as path expressions. A path expression is an identifier
variable followed by the navigation operator ( . ) and a persistence or association field. You
normally use a path expression to narrow the domain for a query by using it in a WHERE
clause or order the retrieved result by using an ORDER BY clause.
An association field can contain either a single-value object or a collection. The association
fields that represent one-to-many and many-to-many associations are collections of types,
and such a path expression is a collection-value path expression. For example, if you have
a many-to-many relationship between Category and Item , you can utilize a query to
find all Category entities that have associated items as follows:
SELECT distinct c
FROM Category c
WHERE c.items isn't EMPTY
Here c.items is a collection type. Such expressions are known as collection-value ex-
pressions. If the association is either many-to-one or one-to-one, then the association fields
are of a specific object type, and those types are known as single-value path expressions.
You can navigate further to other persistence fields or association fields using a single-
value path expression. For example, say you have a many-to-one relationship between
Category and User ; you can navigate to a persistence field such as firstName using
the association field user as follows:
You may also want to navigate to the association field contactDetails to use its email