gpt4 book ai didi

grails - 获取HQL中的两个集合的交集

转载 作者:行者123 更新时间:2023-12-02 15:32:26 25 4
gpt4 key购买 nike

我在使用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

关于grails - 获取HQL中的两个集合的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17517198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com