gpt4 book ai didi

hibernate - Grails GORMS 查找集合属性不为空的所有内容

转载 作者:行者123 更新时间:2023-12-02 22:57:15 25 4
gpt4 key购买 nike

我正在和 Gorms 打架:

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 查询,有什么想法为什么这不起作用吗?

最佳答案

It seems您无法使用动态查找器 (findAllBy*) 查询具有非空集合的对象。您可以使用withCriteria来做到这一点相反:

Product.withCriteria {
isNotEmpty("sub")
}

它使用 Hibernate 的 Criteria API,它比动态查找器更强大一些。 Grails documentation内容很全面。

关于hibernate - Grails GORMS 查找集合属性不为空的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25532287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com