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

时间:2014-08-27 16:22:41

标签: hibernate grails gorm

我正在和风暴打架:

String data = new JSON(Object.executeQuery("from Product p where p.subis not empty"))

工作得很好

但是:

String data = new JSON(Product.findAllBySubIsNotEmpty())

不起作用。错误

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

为了清洁代码的目的,我更喜欢gorms语法到hql查询,任何想法为什么这不起作用?

3 个答案:

答案 0 :(得分:2)

It seems您无法使用动态查找程序(findAllBy*)查询非空集合的对象。您可以使用withCriteria来代替:

Product.withCriteria {
    isNotEmpty("sub")
}

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

答案 1 :(得分:2)

以下findAllBy查询应该有效:

Product.findAllBySubIsNotNull()

您还可以使用where query

Product.where { sub.isEmpty() == false }

答案 2 :(得分:0)

你可以使用像这样的查询

Product.where {
   sub.size() > 0
}

' =='在哪里查询等于sizeGt criteria

相关问题