Grails + Mongodb + Spock: NullPointerException being thrown when doing embedded field query

谁都会走 提交于 2020-01-15 11:34:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!