【发布时间】:2015-05-16 21:40:21
【问题描述】:
我最近将一个 Grails 项目更新到最新的 2.x 版本 2.5.0,以及所有依赖项,包括 Hibernate,它现在是 4.3.5.2。
大部分都可以正常工作,即数据库可以正常写入/检索值,控制器可以正常工作,Spring 安全可以正常工作,等等。但是,现在使用withCriteria 的模型查询之一正在抛出奇怪的错误。
这两个域类看起来像这样:
class MyModel1 {
Integer status
MyModel2 model2
}
class MyModel2 {
Integer range1
Integer range2
}
然后我有这个方法来检查子模型的“范围”字段:
public List<MyModel1> doThing(int low, int hi) {
return MyModel1.withCriteria {
eq("status", SomeStatus.FLAGGED)
model2 {
between("range1", low, hi)
between("range2", low*2, hi*3)
}
}
}
在升级之前,此代码运行良好。现在它抱怨以下异常:
could not resolve property: model2_alias0 of: com.example.MyModel2. Stacktrace follows:
org.hibernate.QueryException: could not resolve property: model2_alias0 of: com.example.MyModel2
at grails.gorm.CriteriaBuilder.invokeMethod(CriteriaBuilder.java:329)
at org.grails.datastore.gorm.GormStaticApi$_withCriteria_closure11.doCall(GormStaticApi.groovy:305)
at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:302)
at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:37)
at org.grails.datastore.gorm.GormStaticApi.withCriteria(GormStaticApi.groovy:304)
at com.example.MyService.doThing(MyService.groovy:42)
(另外,我正在使用 IntelliJ,当我在上面的 withCriteria 块中突出显示 between() 语句时,IntelliJ 告诉我它“无法解析符号'之间'”。可能不相关,IDK。)
【问题讨论】:
标签: grails grails-orm