问题
On one service I'm trying to do something like:
Organization.withCriteria {
eq( "active", true )
eq( "location.region", region)
}
which is working but when calling the method inside a unit test I get:
java.lang.NullPointerException
at org.grails.datastore.mapping.keyvalue.mapping.config.KeyValuePersistentEntity.getPropertyByName(KeyValuePersistentEntity.java:75)
at grails.gorm.CriteriaBuilder.validatePropertyName(CriteriaBuilder.java:954)
at grails.gorm.CriteriaBuilder.eq(CriteriaBuilder.java:435)
at com.apposit.terra.connect.service.OrganizationService.getAllOrganizationsInZone_closure9(OrganizationService.groovy:322)
at grails.gorm.CriteriaBuilder.invokeClosureNode(CriteriaBuilder.java:980)
at grails.gorm.CriteriaBuilder.invokeMethod(CriteriaBuilder.java:314)
at org.grails.datastore.gorm.GormStaticApi.withCriteria_closure11(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)
回答1:
Should be:
Organization.withCriteria {
eq( "active", true )
location {
eq( "region", region)
}
}
If not please file a JIRA at http://jira.grails.org/browse/GPMONGODB
来源:https://stackoverflow.com/questions/28601219/grails-mongodb-spock-nullpointerexception-being-thrown-when-doing-embedded