JPQL Syntax: joins are on the class member

by Bruce on June 14, 2010

In JPQL, if you want to join 2 or more tables explicitly, and not simply walk the relationships in your select or where clauses, you must list the class member of the second+ tables, not the the Object.

select c.keywords from Category c join c.keywords k where c.id = ...
not
select c.keywords from Category c join Keywords k where c.id = ...

I realize the above query could be written as ” from Keywords” but we needed to filter by Category Id and Keyword was mapped to Category via @ManyToMany. Is there still a better way? Please, teach me. Thanks.

Leave a Comment

Previous post:

Next post: