HQL:是另一个集合中一个集合的元素吗?

dea*_*mon 11 collections hibernate hql

我想检查collection(u.organisations)中是否至少包含一个元素(?= excludedOrganisations):

select distinct u from SystemUser u
join u.userGroups g 
join u.organisations o
where 3 in elements(g.permissions) and
EACH_ELEMENT_OF(o) not in (?)
Run Code Online (Sandbox Code Playgroud)

如何EACH_ELEMENT_OF用HQL 表达?

我的最后一次试验是:

select distinct u from SystemUser u 
join u.userGroups g 
where 3 in elements(g.permissions) and 
not exists (
    select org from Organisation org 
    where org in elements(u.organisations)
    and org not in (?)
)
Run Code Online (Sandbox Code Playgroud)

但是我得到了例外:

IllegalArgumentException occurred calling getter of Organisation.id
Run Code Online (Sandbox Code Playgroud)

axt*_*avt 0

我猜你需要一个子查询来用SQL来表达它,因此HQL中也需要子查询:

select u from SystemUser u 
where not exists (
    select 1 from UserGroup g where g.user = u and g not in (?)
)
Run Code Online (Sandbox Code Playgroud)