I recently updated a Grails project to the latest 2.x version, 2.5.0, along with all the dependencies, including Hibernate, which is now at 4.3.5.2.
Everything mostly works, i.e. the database is writing/retrieving values fine, controllers do their thing, Spring security works, etc. However, now one of the model queries using withCriteria
is throwing a weird error.
The two domain classes look something like this:
class MyModel1 {
Integer status
MyModel2 model2
}
class MyModel2 {
Integer range1
Integer range2
}
And then I have this method that does a query that checks the "range" fields of the sub-model:
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)
}
}
}
Prior to upgrading, this code worked fine. Now it complains with the following exception:
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)
(Additionally, I'm using IntelliJ, and when I highlight the between()
statements in the above withCriteria
block IntelliJ informs me that it "Cannot resolve symbol 'between'". Maybe not relevant, IDK.)