Grails域功能不起作用

时间:2016-06-28 07:52:26

标签: function grails intellij-idea

我的问题似乎相当简单,但是从昨天下午起我就难倒了。我的域类功能不起作用(保存和检索记录)。使用intellij Idea,如果我输入" myDomain."自动完成仍会检测到域字段。声明对象后,自动完成仍会建议域属性。无论如何,这就是我得到的:

控制器:

def update(){
    switch(request.getMethod()){
         case 'POST':
             if(params.fire == 'true'){
                 def oldClients = Clients.findAll() /* This is where it breaks. Also 
                 note that all other methods of retrieving data doesn't work either,
                 as well as trying to create and save new records. */
             }
             break
    }
}

// I shortened the domain coz the original has a buttload of fields.
class Clients {
    String CClientId
    String CFirstName
    String CSurname
    String CEmail

    static mapping = {
        id name: "CClientId", generator: "assigned"
        version false
        datasource "dataSourceOld"
        cache usage: 'read-only'
    }

    static constraints = {
        CClientId(maxSize: 12)
        CFirstName(nullable: true, maxSize: 5)
        CSurname(maxSize: 30)
        CEmail(maxSize: 30)
    }
}

还有一点要注意的是,当我尝试以另一种方式声明域的约束时,即CClientId maxSize: 12而不是我在上面声明的方式,我在{{cannot resolve symbol上出现CClientId错误1}}和';', '}' or new line expected后的冒号maxSize错误,

以下是我尝试运行更新操作时出现的错误

.Error 
|
2016-06-28 09:42:02,741 [http-bio-7070-exec-10] ERROR errors.GrailsExceptionResolver  - MissingMethodException occurred when processing request: [POST] /oneyeargift/adminhome/updateAbases - parameters:
fire: true
No signature of method: unipoint.oyg.domain.old.ClientsOyg.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure). Stacktrace follows:
Message: No signature of method: unipoint.oyg.domain.old.ClientsOyg.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
    Line | Method
->>   -2 | newInstance0                    in sun.reflect.NativeConstructorAccessorImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     39 | newInstance                     in     ''
|     27 | newInstance . . . . . . . . . . in sun.reflect.DelegatingConstructorAccessorImpl
|    513 | newInstance                     in java.lang.reflect.Constructor
|    991 | jlrConstructorNewInstance . . . in org.springsource.loaded.ri.ReflectiveInterceptor
|     77 | invoke                          in org.codehaus.groovy.reflection.CachedConstructor
|     71 | doConstructorInvoke . . . . . . in     ''
|     42 | callConstructor                 in org.codehaus.groovy.runtime.callsite.ConstructorSite
|     57 | defaultCallConstructor . . . .  in org.codehaus.groovy.runtime.callsite.CallSiteArray
|    182 | callConstructor                 in org.codehaus.groovy.runtime.callsite.AbstractCallSite
|    194 | callConstructor . . . . . . . . in     ''
|     -1 | findAll                         in unipoint.oyg.domain.old.ClientsOyg$$EPpP6s0O
|     45 | defaultCall . . . . . . . . . . in org.codehaus.groovy.runtime.callsite.CallSiteArray
|    108 | call                            in org.codehaus.groovy.runtime.callsite.AbstractCallSite
|    112 | call . . . . . . . . . . . . .  in     ''
|    880 | updateAbases                    in unipoint.oyg.control.admin.AdminhomeController$$EPpP3IMS
|     -2 | invoke0 . . . . . . . . . . . . in sun.reflect.NativeMethodAccessorImpl
|     39 | invoke                          in     ''
|     25 | invoke . . . . . . . . . . . .  in sun.reflect.DelegatingMethodAccessorImpl
|    597 | invoke                          in java.lang.reflect.Method
|    122 | invoke . . . . . . . . . . . .  in org.springsource.loaded.ri.ReloadedTypeInvoker$2
|   1288 | jlrMethodInvoke                 in org.springsource.loaded.ri.ReflectiveInterceptor
|     69 | invoke . . . . . . . . . . . .  in org.codehaus.groovy.grails.web.servlet.mvc.MixedGrailsControllerHelper
|     -1 | invoke                          in grails.plugin.cache.web.ProxyAwareMixedGrailsControllerHelper
|    348 | handleAction . . . . . . . . .  in org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper
|     -1 | handleAction                    in grails.plugin.cache.web.ProxyAwareMixedGrailsControllerHelper
|    231 | executeAction . . . . . . . . . in org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper
|     -1 | executeAction                   in grails.plugin.cache.web.ProxyAwareMixedGrailsControllerHelper
|    197 | handleURI . . . . . . . . . . . in org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper
|     -1 | handleURI                       in grails.plugin.cache.web.ProxyAwareMixedGrailsControllerHelper
|    118 | handleURI . . . . . . . . . . . in org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper
|     -1 | handleURI                       in grails.plugin.cache.web.ProxyAwareMixedGrailsControllerHelper
|     72 | handleRequest . . . . . . . . . in org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController
|     48 | handle                          in org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter
|    328 | doDispatch . . . . . . . . . .  in org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet
|    852 | doService                       in org.springframework.web.servlet.DispatcherServlet
|    882 | processRequest . . . . . . . .  in org.springframework.web.servlet.FrameworkServlet
|    789 | doPost                          in     ''
|    646 | service . . . . . . . . . . . . in javax.servlet.http.HttpServlet
|    727 | service                         in     ''
|    305 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|    200 | doFilter . . . . . . . . . . .  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     -1 | doFilter                        in grails.plugin.cache.web.filter.ehcache.EhcachePageFragmentCachingFilter
|     63 | doFilter . . . . . . . . . . .  in grails.plugin.cache.web.filter.AbstractFilter
|    346 | invokeDelegate                  in org.springframework.web.filter.DelegatingFilterProxy
|    259 | doFilter . . . . . . . . . . .  in     ''
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|     70 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|     70 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|     70 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|    749 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.ApplicationDispatcher
|    487 | processRequest                  in     ''
|    412 | doForward . . . . . . . . . . . in     ''
|    339 | forward                         in     ''
|    318 | forwardRequestForUrlMappingInfo in org.codehaus.groovy.grails.web.util.WebUtils
|    283 | forwardRequestForUrlMappingInfo in     ''
|    274 | forwardRequestForUrlMappingInfo in     ''
|    203 | doFilterInternal                in org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter
|     76 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|     82 | doFilterInternal                in com.linkedin.grails.profiler.ProfilerFilter
|     76 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|    206 | obtainContent                   in org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter
|    152 | doFilter . . . . . . . . . . .  in     ''
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|     -1 | call                            in javax.servlet.FilterChain$doFilter
|     45 | doFilter . . . . . . . . . . .  in org.grails.plugin.resource.DevModeSanityFilter
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|    369 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    109 | invoke . . . . . . . . . . . .  in org.springframework.security.web.access.intercept.FilterSecurityInterceptor
|     83 | doFilter                        in     ''
|    381 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     97 | doFilter                        in org.springframework.security.web.access.ExceptionTranslationFilter
|    381 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     78 | doFilter                        in org.springframework.security.web.authentication.AnonymousAuthenticationFilter
|    381 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    119 | doFilter                        in org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter
|    381 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     54 | doFilter                        in org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter
|    381 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    187 | doFilter                        in org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
|     40 | doFilter . . . . . . . . . . .  in org.codehaus.groovy.grails.plugins.springsecurity.RequestHolderAuthenticationFilter
|    381 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     79 | doFilter . . . . . . . . . . .  in org.codehaus.groovy.grails.plugins.springsecurity.MutableLogoutFilter
|    381 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     79 | doFilter . . . . . . . . . . .  in org.springframework.security.web.context.SecurityContextPersistenceFilter
|    381 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    168 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy
|    346 | invokeDelegate                  in org.springframework.web.filter.DelegatingFilterProxy
|    259 | doFilter . . . . . . . . . . .  in     ''
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|    113 | doFilter                        in io.jdev.miniprofiler.servlet.ProfilingFilter
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|     69 | doFilterInternal . . . . . . .  in org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter
|     76 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|     66 | doFilterInternal . . . . . . .  in org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter
|     76 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|     88 | doFilterInternal . . . . . . .  in org.springframework.web.filter.CharacterEncodingFilter
|     76 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    346 | invokeDelegate . . . . . . . .  in org.springframework.web.filter.DelegatingFilterProxy
|    259 | doFilter                        in     ''
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|    222 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.StandardWrapperValve
|    123 | invoke                          in org.apache.catalina.core.StandardContextValve
|    171 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.StandardHostValve
|     99 | invoke                          in org.apache.catalina.valves.ErrorReportValve
|    118 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.StandardEngineValve
|    408 | service                         in org.apache.catalina.connector.CoyoteAdapter
|   1023 | process . . . . . . . . . . . . in org.apache.coyote.http11.AbstractHttp11Processor
|    589 | process                         in org.apache.coyote.AbstractProtocol$AbstractConnectionHandler
|    312 | run . . . . . . . . . . . . . . in org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor
|    895 | runTask                         in java.util.concurrent.ThreadPoolExecutor$Worker
|    918 | run . . . . . . . . . . . . . . in     ''
^    662 | run                             in java.lang.Thread

任何帮助都会非常感激。

2 个答案:

答案 0 :(得分:1)

我认为问题在于您命名域类属性的方式。 您是否尝试过以下操作?

class Clients {
    String cClientId
    String cFirstName
    String cSurname
    String cEmail

    static mapping = {
        id name: "cClientId", generator: "assigned"
        version false
        datasource "dataSourceOld"
        cache usage: 'read-only'
    }

    static constraints = {
        cClientId(maxSize: 12)
        cFirstName(nullable: true, maxSize: 5)
        cSurname(maxSize: 30)
        cEmail(maxSize: 30)
    }
}

因此,如果您按如下方式声明约束:

static constraints = {
    cClientId maxSize: 12
    cFirstName nullable: true, maxSize: 5
    cSurname maxSize: 30
    cEmail maxSize: 30
}

这是有效的;)

答案 1 :(得分:-1)

看起来Grails不会将您的客户端识别为域对象,这就是为什么所有GORM动态方法(获取,列出,查找,保存,更新......)都不起作用的原因。