Grails GORMS 找到所有集合属性不为空的地方

Seb*_*ger 3 grails hibernate grails-orm

我正在与gorms战斗:

String data = new JSON(Object.executeQuery("from Product p where p.subis not empty"))
Run Code Online (Sandbox Code Playgroud)

工作正常

然而:

String data = new JSON(Product.findAllBySubIsNotEmpty())
Run Code Online (Sandbox Code Playgroud)

不起作用。错误

No signature of method: com.path.Object.findAllBySubIsNotEmpty() is applicable for argument types: () values: []
Run Code Online (Sandbox Code Playgroud)

为了干净的代码,我更喜欢 gorms 语法而不是 hql 查询,任何想法为什么这行不通?

Paw*_*cyk 5

似乎您无法使用动态查找器 ( findAllBy*)查询具有非空集合的对象。您可以withCriteria改为使用:

Product.withCriteria {
    isNotEmpty("sub")
}
Run Code Online (Sandbox Code Playgroud)

它使用 Hibernate 的 Criteria API,它比动态查找器更强大一些。Grails 文档对此非常全面。