有没有一个“不在”? GORM 中的等效项?
这可以在 createCriteria() 中转换吗?
SELECT * FROM node WHERE (node.type = 'act' AND nid NOT IN (SELECT nid FROM snbr_act_community)) LIMIT 10
我知道有一个“in”运算符,这就是我到目前为止所拥有的:
def c = VolunteerOpportunity.createCriteria()
def matchingActs = c.list {
node {
eq('type', 'act')
}
maxResults(10)
}
只是想看看这是否可能。否则,我想这在 HQL 中是可能的,对吗?
Is this possible to convert in createCriteria()?
SELECT * FROM node WHERE (node.type = 'act' AND nid NOT IN (SELECT nid FROM snbr_act_community)) LIMIT 10
I know there's a 'in' operator and here's what I have so far:
def c = VolunteerOpportunity.createCriteria()
def matchingActs = c.list {
node {
eq('type', 'act')
}
maxResults(10)
}
Just want to see if this is possible. Otherwise, I guess this is possible in HQL right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
感谢 Sammyrulez 提供的代码。从中得到了一个想法。测试了一下,但没有用。我修复了它,这是最终的工作代码:
现在我知道如何使用“not”运算符。多谢!
thanks Sammyrulez for the code. got an idea from that. tested it but it didn't work. i fixed it and here's the final working code:
now i know how to use 'not' operator. thanks a lot!
我自己没有尝试过,但是查看 Grails 文档和 hibernate api,您可以使用 Hibernate Criteria API 的 Restrictions 类中找到的静态方法在此构建器映射上创建节点 1。所以就像
既然你将 in 方法(返回一个 Criterion)与 not 方法(将 Criterion 作为参数并返回一个否定版本)链接起来
not tried it myself but looking at the Grails doc and hibernate api you create nodes on this builder map with the static methods found in the Restrictions class of the Hibernate Criteria API 1. So something like
Since you chain the in method (that returns a Criterion) with the not method (that takes a Criterion as argument and returns a negated version)
这是解决方案:
this is the solution :
根据有关创建条件的 Grails 文档此处,您可以使用类似这样的内容:
在此示例中,您有一个名为
"age"
的属性,并且您想要获取不在 18 到 65 之间的行。当然,[18..65 ]
部分可以替换为您需要的任何值列表或范围。According to Grails documentation about creating criteria here, you can use something like this:
In this example, you have a property named
"age"
and you want to get rows that are NOT between 18 and 65. Of course, the[18..65]
part can be substituted with any list of values or range you need.请记住:在这种情况下,您不必使用括号,您可以使用
inList
,例如:Just remembering: in this case you don't have to use parenthesis and you can use
inList
, for example: