Question

Simple JPA/JPQL question. I have an entity with a ManyToMany relationship:

@Entity
public class Employee {      
  @ManyToMany
  @JoinTablename="employee_project"
      joinColumns={@JoinColumn(name="employee_id"}
      inverseJoinColumns={@JoinColumn(name="project_id"})
  private List<Project> projects;

What is the JPQL query to return all the Employees that do not have any projects?

Was it helpful?

Solution

from Employee e where not exists elements(e.projects)

or

from Employee e where size(e.projects) = 0

OTHER TIPS

JQPL does have dedicated IS [NOT] EMPTY comparison operator for checking is collection empty:

SELECT e FROM Employee e WHERE e.projects IS EMPTY
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top