Similar to this post, I have these (almost the same) classes:
public class Project {
@ManyToMany
private Set<Person> resources;
// get and set of resources
}
public class Person {
}
The difference is that my properties are private (using beans as entities).
The question is: how would I create a query to return all projects of a determined person (in JPQL and/or using CriteriaQuery)?
I found all these other similar questions, but none helped me, because all of them rely on the navigation from Project
to Person
(which doesn't exist querying from Person
):
I wouldn't like to insert a property inside 'Person' just to be able to make the query, because it doesn't make sense in my model.
Thanks!!
select project from Project project
join project.resources person
where person.id = :personId
I'll let you translate this to criteria if you really want it, but I don't hink using Criteria for such a basic static query offers any advantage.