简单的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查询是什么?
答案 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