java.lang.ClassCastException:[Ljava.lang.Object;无法转换为com.sx.mcqs.model

时间:2012-08-10 07:41:47

标签: hibernate

questions=dao.getNamedQueryResultList("getUnansweredQuestionsByCategory", new Object[]{strUser});



    for(Question selectedResumes:questions) {
          //do something with the SelectedResumes object
        System.out.println("Unanswered::"+selectedResumes.getQuestion());
    }

=============================================== ======================= -

发生以下错误:

  

java.lang.ClassCastException:[Ljava.lang.Object;无法施展   com.sx.mcqs.model.Question at   com.sx.mcqs.service.QuestionService.findRelatedQuestionsGame(QuestionService.java:142)     在   com.sx.mcqs.service.QuestionService $$ FastClassByCGLIB $$ cd78275c.invoke()     在net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)at   org.springframework.aop.framework.Cglib2AopProxy $ CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)     在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)     在   org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)     在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)     在   org.springframework.aop.framework.Cglib2AopProxy $ DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)     在   com.sx.mcqs.service.QuestionService $$ EnhancerByCGLIB $$ f6d3276_2.findRelatedQuestionsGame()     在   com.sx.mcqs.controller.QuestionController.selectcategory(QuestionController.java:182)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     在java.lang.reflect.Method.invoke(Method.java:597)at   org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)     在   org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)     在   org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)     在   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)     在   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)     在   org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)     在   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)     在   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)     在   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)     在   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:621)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:722)at at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:58)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在com.sx.mcqs.filter.GzipFilter.doFilter(GzipFilter.java:86)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:147)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   com.sx.mcqs.filter.UserSessionFilter.doFilter(UserSessionFilter.java:62)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:565)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:309)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.runTask(ThreadPoolExecutor.java:886)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:908)     在java.lang.Thread.run(Thread.java:619)

1 个答案:

答案 0 :(得分:3)

上面的代码假定命名查询返回一个问题列表,但它返回一个对象数组。要返回问题列表,查询应该类似于

select question from Question question ...

但查询可能看起来像

select question.foo, question.bar, ...

如果没有看到执行的查询,就很难给出更详细的答案。