在ManyToMany关系中没有项目的实体的JPQL

时间:2009-10-06 21:31:47

标签: java jpa jpql

简单的JPA / JPQL问题。我有一个具有ManyToMany关系的实体:

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

返回所有没有任何项目的员工的JPQL查询是什么?

2 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:2)

JQPL确实有专门的IS [NOT] EMPTY比较运算符,用于检查集合为空:

SELECT e FROM Employee e WHERE e.projects IS EMPTY