Hibernate Grails命名查询不在

Hibernate Grails命名查询不在,hibernate,grails,criteria,named-query,Hibernate,Grails,Criteria,Named Query,试图找到一种简洁的方法,用NOT IN子句创建命名查询。限制类似乎没有“notin”构造。有人知道这样做的好方法吗 解决方案: static namedQueries = { activeOnly { eq 'active', true } open { ne 'state', this.STATE_COMPLETED } my { user ->

试图找到一种简洁的方法,用NOT IN子句创建命名查询。限制类似乎没有“notin”构造。有人知道这样做的好方法吗

解决方案

static namedQueries = {
        activeOnly {
            eq 'active', true
        }
        open {
            ne 'state', this.STATE_COMPLETED
        }
        my { user ->
            or {
                eq 'createdBy', user
                eq 'reviewer', user
                eq 'assignee', user
                eq 'requestedFor', user
                ilike 'notifyList', "%$user%"
            }
        }
        topLevel {
            not {'in'('type', [RequestType.Part])}
        }
    }
注意:必须引用“in”一词,因为它是保留的

这些命名查询的使用方式如下:

Request.activeOnly.open.topLevel.list(params)
Book.findAll("from Book b where b.author not in (?)", ['Borges', 'Sabato', 'Cortazar'])

也许是这样的:

Request.activeOnly.open.topLevel.list(params)
Book.findAll("from Book b where b.author not in (?)", ['Borges', 'Sabato', 'Cortazar'])
或者使用一个标准

Book.withCriteria {
    not {
        'in'('author', ['Borges', 'Sabato', 'Cortazar'])
    }
}

“in”标准方法的文档也有一个链接的“not”方法。

谢谢您的回复。这可能有效,但不是命名查询。命名查询使用CriteriaAPI创建和缓存准备好的语句。谢谢您的时间。修正了语法。inList是为约束保留的,但在工作中引用“in”。