Grails GORM(Hibernate)查询

bsr*_*bsr 2 grails hibernate grails-orm

我正在尝试在GORM中执行以下sql语句

select * from table1 where table1.x not in
      (select x from table 2 where y='something');
Run Code Online (Sandbox Code Playgroud)

所以,我有两个表,需要找到表1中不在表2中的条目.在Grails中

def xx= table2.findByY('something')
    def c = table1.createCriteria()
    def result= c.list {
      not (
        in('x', xx)
    )
}
Run Code Online (Sandbox Code Playgroud)

语法错了,我不知道如何 sql逻辑中模拟.

作为一个学习点,如果有人也可以告诉我为什么grails/groovy中的减号( - )运算符不能与列表一起使用.我尝试单独获取x和y,并执行x.minus(y),但它不会更改列表.我在Grails列表上的Groovy上看到了一个解释- 没有用?,但我希望定义的列表是本地的.

非常感谢.

Ste*_*sen 5

嗯,我只是自己学习GORM,但我看到的一件事是,在groovy 是一个保留字,因此需要像'in'一样被转义