开发者

JPQL for Entities with No Items in ManyToMany Relationship

开发者 https://www.devze.com 2022-12-08 01:14 出处:网络
Simple JPA/JPQL question. I have an entity with a ManyToMany relationship: @Entity public class Employee {

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 t开发者_如何学编程hat do not have any projects?


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

or

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


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

SELECT e FROM Employee e WHERE e.projects IS EMPTY
0

精彩评论

暂无评论...
验证码 换一张
取 消