某个实体:
@Entity
@Table(name="document")
public class Document {
...
@ManyToMany
public Set<User> accessors;
....
}
查询所有的包含某个特定user的Documents的方法
1、 用join
select distinct d from Document d inner join d.accessors a where a.id = :id
2、MEMBER OF
关键字
SELECT d FROM Document AS d WHERE :user MEMBER OF d.accessors
这种方法比第一种简单些,但是只能传入user实体,而不是user id.
from:JPA JPQL: select items when attribute of item (list/set) contains another item