HQL:一个集合的元素是否在另一个集合中?
我想检查一个集合 (u.organizations
) 中的至少一个元素是否包含在另一个集合 (?
= exceptedOrganizations) 中:
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 (?)
如何表达 使用 HQL 的 EACH_ELEMENT_OF
?
我的最后一次试验是:
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 (?)
)
但我得到了例外:
IllegalArgumentException occurred calling getter of Organisation.id
I want to check whether at least one element of a collection (u.organisations
) is contained in another collection (?
= 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 (?)
How can I express the EACH_ELEMENT_OF
with HQL?
My last trial is:
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 (?)
)
But I get the exception:
IllegalArgumentException occurred calling getter of Organisation.id
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜你需要一个子查询来用SQL来表达它,因此HQL中也需要子查询:
I guess you need a subquery to express it in SQL, therefore subquery is also needed in HQL:
这是 Hibernate 文档中的经典示例:
在您的情况下,这将是:
我假设 Organization 实体有一个 id 字段,您可以传入 id 列表。
This is the classical example from Hibernate documentation:
In your case, this would be:
I'm assuming the Organisation entity has an id field and you can pass in the list of ids.