0

我在使用 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 中解决这个问题。

有任何想法吗?

4

1 回答 1

1

Try this:

select o from Object as o 
join o.otherObjects as otherObject 
where 
    otherObject in :allowedotherobjects 
    and otherObject not in :excludedotherobjects
于 2013-07-08T01:04:44.280 回答