我在使用HQL时遇到了一些麻烦。
我想做一个相当复杂的查询,我有以下域对象(简化):
class SomeObject {
Set<SomeOtherObject> 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中解决这个问题
有什么想法吗?我真的很感谢你的帮助!
答案 0 :(得分:1)
试试这个:
select o from Object as o
join o.otherObjects as otherObject
where
otherObject in :allowedotherobjects
and otherObject not in :excludedotherobjects