grails 中的 NullPointerException 错误

NullPointerException error in grails

我真的很生气。

我的目标是保存其中state/region一个对象,所以我设置了这个域class:

class State {

    String stateName
    String stateIsoCode

    static hasMany = [regions: Region]

    static constraints = {
        stateIsoCode unique:true
        stateName unique:true
    }
}


class Region {

    String regionName
    String regionIsoCode

    static belongsTo = [state: State]
    static hasMany = [provinces: Province]

    static constraints = {
        regionIsoCode unique:true
        regionName unique:true
    }
}

当有人想插入他的对象的位置时,他可以使用 select 来完成,该 select 的值是州或地区的 isoCode

所以在控制器中我尝试这样设置对象的位置:

materialInstance.state = State.findByStateIsoCode(params?.state)
materialInstance.region = Region.findByRegionIsoCodeAndState(params.region,materialInstance.state)

我收到这个错误:

| Error 2015-01-17 19:04:19,923 [http-bio-8080-exec-12] ERROR errors.GrailsExceptionResolver  - NullPointerException occurred when processing...
Message: null
    Line | Method
->>  163 | removeBatchLoadableEntityKey    in org.hibernate.engine.spi.BatchFetchQueue
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    388 | addEntity                       in org.hibernate.engine.internal.StatefulPersistenceContext
|    461 | addEntity . . . . . . . . . . . in     ''
|    143 | makeEntityManaged               in org.hibernate.action.internal.AbstractEntityInsertAction
|    201 | addResolvedEntityInsertAction . in org.hibernate.engine.spi.ActionQueue
|    179 | addInsertAction                 in     ''
|    214 | addAction . . . . . . . . . . . in     ''
|    324 | addInsertAction                 in org.hibernate.event.internal.AbstractSaveEventListener
|    288 | performSaveOrReplicate . . . .  in     ''
|    194 | performSave                     in     ''
|    125 | saveWithGeneratedId . . . . . . in     ''
|    209 | saveWithGeneratedOrRequestedId  in org.hibernate.event.internal.DefaultSaveOrUpdateEventListener
|    194 | entityIsTransient . . . . . . . in     ''
|    114 | performSaveOrUpdate             in     ''
|     90 | onSaveOrUpdate . . . . . . . .  in     ''
|    684 | fireSaveOrUpdate                in org.hibernate.internal.SessionImpl
|    676 | saveOrUpdate . . . . . . . . .  in     ''
|    235 | cascade                         in org.hibernate.engine.spi.CascadingActions
|    350 | cascadeToOne . . . . . . . . .  in org.hibernate.engine.internal.Cascade
|    293 | cascadeAssociation              in     ''
|    161 | cascadeProperty . . . . . . . . in     ''
|    379 | cascadeCollectionElements       in     ''
|    319 | cascadeCollection . . . . . . . in     ''
|    296 | cascadeAssociation              in     ''
|    161 | cascadeProperty . . . . . . . . in     ''
|    118 | cascade                         in     ''
|    167 | cascadeOnFlush . . . . . . . .  in org.hibernate.event.internal.AbstractFlushingEventListener
|    158 | prepareEntityFlushes            in     ''
|     91 | flushEverythingToExecutions . . in     ''
|     61 | onAutoFlush                     in org.hibernate.event.internal.DefaultAutoFlushEventListener
|   1191 | autoFlushIfRequired . . . . . . in org.hibernate.internal.SessionImpl
|   1675 | list                            in     ''
|    380 | list . . . . . . . . . . . . .  in org.hibernate.internal.CriteriaImpl
|    105 | getResult                       in org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractFindByPersistentMethod
|     67 | doInHibernate . . . . . . . . . in org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractFindByPersistentMethod
|    179 | doExecute                       in org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateTemplate
|    123 | execute . . . . . . . . . . . . in     ''
|     62 | doInvokeInternalWithExpressions in org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractFindByPersistentMethod
|    544 | doInvokeInternal . . . . . . .  in org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractClausedStaticPersistentMethod
|    418 | doInvokeInternal                in     ''
|     79 | invoke . . . . . . . . . . . .  in org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractStaticPersistentMethod
|     72 | invoke                          in     ''
|     -1 | call . . . . . . . . . . . . .  in org.codehaus.groovy.grails.commons.metaclass.StaticMethodInvocation$invoke[=12=]
|     45 | defaultCall                     in org.codehaus.groovy.runtime.callsite.CallSiteArray
|     -1 | call . . . . . . . . . . . . .  in org.codehaus.groovy.grails.commons.metaclass.StaticMethodInvocation$invoke[=12=]
|    102 | doCall                          in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
|     -1 | call . . . . . . . . . . . . .  in     ''
|     59 | invoke                          in org.codehaus.groovy.runtime.metaclass.ClosureStaticMetaMethod
|    324 | doMethodInvoke . . . . . . . .  in groovy.lang.MetaMethod
|     43 | invoke                          in org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite
|     88 | call . . . . . . . . . . . . .  in     ''
|    116 | call                            in org.codehaus.groovy.runtime.callsite.AbstractCallSite
|     46 | $tt__save . . . . . . . . . . . in com.circularMaterial.core.MaterialController$$EP1eJsbQ
|     -1 | $tt__save                       in com.circularMaterial.core.MaterialController$$DP1eJsbQ
|     -2 | invoke0 . . . . . . . . . . . . in sun.reflect.NativeMethodAccessorImpl
|     62 | invoke                          in     ''
|     43 | invoke . . . . . . . . . . . .  in sun.reflect.DelegatingMethodAccessorImpl
|    483 | invoke                          in java.lang.reflect.Method
|    122 | invoke . . . . . . . . . . . .  in org.springsource.loaded.ri.ReloadedTypeInvoker
|   1299 | jlrMethodInvoke                 in org.springsource.loaded.ri.ReflectiveInterceptor
|     90 | invoke . . . . . . . . . . . .  in org.codehaus.groovy.reflection.CachedMethod
|    324 | doMethodInvoke                  in groovy.lang.MetaMethod
|   1207 | invokeMethod . . . . . . . . .  in groovy.lang.MetaClassImpl
|   1110 | invokeMethod                    in groovy.lang.ExpandoMetaClass
|   1016 | invokeMethod . . . . . . . . .  in groovy.lang.MetaClassImpl
|    423 | call                            in groovy.lang.Closure
|     -1 | call . . . . . . . . . . . . .  in com.circularMaterial.core.MaterialController$_save_closure4
|    439 | call                            in groovy.lang.Closure
|     -1 | call . . . . . . . . . . . . .  in com.circularMaterial.core.MaterialController$_save_closure4
|     88 | doInTransaction                 in org.codehaus.groovy.grails.orm.support.GrailsTransactionTemplate
|    133 | execute . . . . . . . . . . . . in org.springframework.transaction.support.TransactionTemplate
|     85 | execute                         in org.codehaus.groovy.grails.orm.support.GrailsTransactionTemplate
|     -1 | save . . . . . . . . . . . . .  in com.circularMaterial.core.MaterialController$$EP1eJsbQ
|     -2 | invoke0                         in sun.reflect.NativeMethodAccessorImpl
|     62 | invoke . . . . . . . . . . . .  in     ''
|     43 | invoke                          in sun.reflect.DelegatingMethodAccessorImpl
|    483 | invoke . . . . . . . . . . . .  in java.lang.reflect.Method
|    122 | invoke                          in org.springsource.loaded.ri.ReloadedTypeInvoker
|   1299 | jlrMethodInvoke . . . . . . . . in org.springsource.loaded.ri.ReflectiveInterceptor
|    154 | invoke                          in org.codehaus.groovy.grails.web.servlet.mvc.MixedGrailsControllerHelper
|    375 | handleAction . . . . . . . . .  in org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper
|    252 | executeAction                   in     ''
|    205 | handleURI . . . . . . . . . . . in     ''
|    126 | handleURI                       in     ''
|     72 | handleRequest . . . . . . . . . in org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController
|     50 | handle                          in org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter
|    347 | doDispatch . . . . . . . . . .  in org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet
|    870 | doService                       in org.springframework.web.servlet.DispatcherServlet
|    961 | processRequest . . . . . . . .  in org.springframework.web.servlet.FrameworkServlet
|    863 | doPost                          in     ''
|    646 | service . . . . . . . . . . . . in javax.servlet.http.HttpServlet
|    837 | service                         in org.springframework.web.servlet.FrameworkServlet
|    727 | service . . . . . . . . . . . . in javax.servlet.http.HttpServlet
|    303 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|     52 | doFilter                        in org.apache.tomcat.websocket.server.WsFilter
|    241 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter                        in     ''
|    198 | doFilter . . . . . . . . . . .  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter                        in grails.plugin.cache.web.filter.AbstractFilter
|    344 | invokeDelegate . . . . . . . .  in org.springframework.web.filter.DelegatingFilterProxy
|    261 | doFilter                        in     ''
|    241 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter                        in     ''
|    101 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|    101 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter                        in     ''
|    101 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|    748 | invoke                          in org.apache.catalina.core.ApplicationDispatcher
|    486 | processRequest . . . . . . . .  in     ''
|    411 | doForward                       in     ''
|    338 | forward . . . . . . . . . . . . in     ''
|    178 | forwardRequestForUrlMappingInfo in org.codehaus.groovy.grails.web.mapping.UrlMappingUtils
|    144 | forwardRequestForUrlMappingInfo in     ''
|    135 | forwardRequestForUrlMappingInfo in     ''
|    216 | doFilterInternal . . . . . . .  in org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter
|    107 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter                        in     ''
|    330 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    118 | invoke                          in org.springframework.security.web.access.intercept.FilterSecurityInterceptor
|     84 | doFilter . . . . . . . . . . .  in     ''
|    342 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    113 | doFilter . . . . . . . . . . .  in org.springframework.security.web.access.ExceptionTranslationFilter
|    342 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     53 | doFilter . . . . . . . . . . .  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|    342 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    146 | doFilter . . . . . . . . . . .  in org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter
|    342 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    154 | doFilter . . . . . . . . . . .  in org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter
|    342 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    199 | doFilter . . . . . . . . . . .  in org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
|     49 | doFilter                        in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|    342 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     82 | doFilter                        in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|    342 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     87 | doFilter                        in org.springframework.security.web.context.SecurityContextPersistenceFilter
|    342 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    192 | doFilterInternal                in org.springframework.security.web.FilterChainProxy
|    160 | doFilter . . . . . . . . . . .  in     ''
|    344 | invokeDelegate                  in org.springframework.web.filter.DelegatingFilterProxy
|    261 | doFilter . . . . . . . . . . .  in     ''
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|     69 | doFilterInternal                in org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter
|    107 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|     67 | doFilterInternal                in org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter
|    107 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|     88 | doFilterInternal                in org.springframework.web.filter.CharacterEncodingFilter
|    107 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    344 | invokeDelegate                  in org.springframework.web.filter.DelegatingFilterProxy
|    261 | doFilter . . . . . . . . . . .  in     ''
|    241 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    208 | doFilter . . . . . . . . . . .  in     ''
|    220 | invoke                          in org.apache.catalina.core.StandardWrapperValve
|    122 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.StandardContextValve
|    171 | invoke                          in org.apache.catalina.core.StandardHostValve
|    103 | invoke . . . . . . . . . . . .  in org.apache.catalina.valves.ErrorReportValve
|    116 | invoke                          in org.apache.catalina.core.StandardEngineValve
|    408 | service . . . . . . . . . . . . in org.apache.catalina.connector.CoyoteAdapter
|   1070 | process                         in org.apache.coyote.http11.AbstractHttp11Processor
|    611 | process . . . . . . . . . . . . in org.apache.coyote.AbstractProtocol$AbstractConnectionHandler
|    316 | run                             in org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor
|   1142 | runWorker . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
|    617 | run                             in java.util.concurrent.ThreadPoolExecutor$Worker
|     61 | run . . . . . . . . . . . . . . in org.apache.tomcat.util.threads.TaskThread$WrappingRunnable
^    745 | run                             in java.lang.Thread

我不明白是什么原因造成的,此外,如果我评论保存状态和区域的代码片段,我会通过控制器(我得到错误,因为它们不是可为空的字段)然后我取消注释,它有效。

我正在使用带有 nosql 数据库的 grails,并且正在调试环境

谢谢

由底层 Hibernate 问题引起 https://hibernate.atlassian.net/browse/HHH-11721