Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPQL for Entities with No Items in ManyToMany Relationship

Tags:

java

jpa

jpql

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?

like image 332
Tim Avatar asked Dec 29 '22 14:12

Tim


1 Answers

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

or

from Employee e where size(e.projects) = 0
like image 116
ChssPly76 Avatar answered Feb 06 '23 19:02

ChssPly76