grails - GORM where 对嵌入对象的查询

标签 grails grails-orm

我有域类 A 和 B 如下:

class A {
    String prop1
    String prop2
    B prop3

    static embedded = ['prop3']
}

class B {
    String prop4
    String prop5
}

当我想这样查询时:
def q = A.where { prop3.prop4 == 'bla' }
def list = q.list()

我收到以下异常:
Cannot get property 'javaClass' on null object. Stacktrace follows:

在“def q = A.where ...”行上。

任何线索是什么问题?我已经检查过这个:

http://grails.1312388.n4.nabble.com/GORM-embedded-object-issue-td1379137.html

但是我不太清楚如何“直接调用他们”。在 GORM 中查询嵌入对象的任何其他方式?

最佳答案

我最终放弃了 where 查询并采用了 DetachedCriteria 方法。为我提供与 where 查询相同的灵活性,但适用于嵌入式域对象:

def criteria = new DetachedCriteria(A).build {
    eq 'prop1', 'bla2'
}
criteria = criteria.build {
   eq 'prop3.prop4', 'bla'
}
def list = criteria.list()

关于grails - GORM where 对嵌入对象的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18235180/

相关文章:

spring - Spring Boot框架需要Spring安全管理控制台

grails - 在hasMany条件中比较属性

grails - GORM - all-delete-orphan 不起作用

java - Hibernate PersistentMap 返回错误的值

Grails 选择标记结果

grails - 如何删除 DbdocController?

grails - 标准的单元测试模拟

grails - Can Grails 3.3 字段插件 f :display show many-to-many

hibernate - 映射异常 : Could not determine Type

grails - Quartz 作业中的 org.hibernate.LazyInitializationException