grails - 通过继承类的字段进行GORM分离查询

标签 grails gorm grails-domain-class

我有Parent类以及从它继承的两个Child1Child2:

class Parent { }
class Child1 extends Parent {
    String prop1
}
class Child2 extends Parent {
    String prop2
}

现在我需要写出选择所有父级类别的内容,但要使用prop1prop2的标准,即类似这样的内容

DetachedCriteria crit = Parent.where {
    (prop1 == 'Some value') || (prop2 == 'Some value')
}
crit.list()

我怎样才能做到这一点?

最佳答案

简短的答案是,您不能基于子类的属性来查询类,除非它们是继承的。父级在您的示例中没有子类的属性的概念,因为它们不是继承的,因此无法进行查询。最好的解决方案是分别查询每个子类,然后合并结果。

关于grails - 通过继承类的字段进行GORM分离查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20954616/

相关文章:

grails - 多个联接的排序问题

hibernate - Grails 3.3.6是否未配置GORM?

Grails 域验证器不工作

tomcat - Grails:Tomcat 不会在产品中干净地关闭

grails - IntelliJ 的 dirtyPropertyNames "cannot resolve symbol"

grails - Grails 3.0.0缺少findOrCreateBy()

google-app-engine - 使用Grails/GORM在Appengine上建立一对多关系

spring - chalice 3;使用 Spring Security 查看自己的数据

hibernate - 使用Hibernate/GORM导致java.sql.BatchUpdateException错误

rest - 使用wslite从rest响应中获取excel文件