Multiple JPA Joins

I have these classes

class Project { @ManyToOne Company owner; @ManyToMany Set<Person> resources; } class Company { @ManyToOne Country country; } class Person { } 

How can I write JPQL to get all the resources working on projects for companies in a specific country?

The following shows what is not working (using DataNucleus)

 SELECT r FROM Project p JOIN p.resources r JOIN p.owner c WHERE c.country = :country 

It tries to join r with c and, of course, does not have the owner property, and a NullPointerException is thrown inside the DataNucleus.

+4
source share
1 answer

This should do what you expect:

 SELECT resource FROM Project p INNER JOIN p.resources as resource 

EDIT:

I forgot part of the original question:

 SELECT resource FROM Project p INNER JOIN p.resources as resource where p.owner.country = :country 
+2
source

All Articles