我有域类 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/