[英]Get the intersection of two sets in HQL
我在使用 HQL 时遇到了一些麻烦。
我想做一个相当复杂的查询,我有以下域对象(简化):
class SomeObject {
Set<SomeOtherObject> otherObjects
}
我现在想要获取包含一个或多个其他对象的指定列表的所有对象。 此外,我还想要一个黑名单,该对象不得包含其他对象。
我做到了这一点,我只能指定一个黑名单项目和一个“允许的”otherObjects 列表:
select o from Object as o
join o.otherObjects as otherObject
where
otherObject in :allowedotherobjects
and :excludedotherobject not in elements(o.otherObjects)
基本上我想要这样的东西(这是不可能的):
select o from Object as o
join o.otherObjects as otherObject
where
otherObject in :allowedotherobjects
and elements(:excludedotherobjects) not in elements(o.otherObjects)
顺便说一句,这是我正在进行的一个 grails 项目,但我想在 HQL 中解决这个问题。
有什么想法吗?
试试这个:
select o from Object as o
join o.otherObjects as otherObject
where
otherObject in :allowedotherobjects
and otherObject not in :excludedotherobjects
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.