我有一段代码,我在其中调用dao方法并根据调用结果返回diff对象的列表。 调用者方法根据查询结果返回List。 被调用的方法具有如下原始类型的声明。 该代码可以很好地编译,但是在出现转换问题时某些查询会出现运行时错误。
public List loadTransformedObjectWithNativeSQL(String paramString, Map paramMap, Object[] paramArrayOfObject, Class paramClass)
{ .......
调用方方法如下:
public List<ModelData> getModelQuestionaire(Map<String, Object> params) {
String sql = getSql("getModelQuestionaire");
Object[] values = new Object[2];
values[0] = params.get("contractType");
values[1] = params.get("modelVerID");
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
map.put("quesID", StringType.INSTANCE);
map.put("questionaire", StringType.INSTANCE);
map.put("quesValueType", StringType.INSTANCE);
map.put("valueID", StringType.INSTANCE);
map.put("quesValue", StringType.INSTANCE);
map.put("noOfAnswer", StringType.INSTANCE);
map.put("modelQuesValueID", StringType.INSTANCE);
return loadTransformedObjectWithNativeSQL(sql, map, values, ModelData.class);
}
现在,对于此方法,我将返回ModelData类。对于其他方法,我可能会返回其他一些类。
对被调用方法进行类型安全的最佳方法是什么。
我尝试过List<?>
,但遇到编译错误。
如果我仅保留列表,则会收到此运行时错误:
17:18:58,121 INFO [stdout] (default task-21) *************SQLQuery[OBJ]*****************Select q.ques_id quesid,q.question questionaire ,q.value_typ quesValueType,a.value_id valueID,a.question_value quesValue,(select count(1) from cost_ques_value c where c.ques_id=q.ques_id) noOfAnswer, nvl(v.value_id,'0') modelQuesValueID from cost_questionaire q,cost_ques_value a, cost_mdl_ver_t_c_ques_value v where q.ques_id=a.ques_id and q.Category_level=? and q.ques_id = v.ques_id(+) and v.mdl_ver_id(+)=? and q.rec_status_ind=1 and a.rec_status_ind=1 order by q.ques_id
17:18:58,259 ERROR [stderr] (default task-21) java.lang.ClassCastException: com.ge.energy.common.data.config.ModelData cannot be cast to java.util.Map
17:18:58,261 ERROR [stderr] (default task-21) at org.hibernate.property.access.internal.PropertyAccessMapImpl$SetterImpl.set(PropertyAccessMapImpl.java:102)
17:18:58,261 ERROR [stderr] (default task-21) at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer.java:78)
17:18:58,262 ERROR [stderr] (default task-21) at org.hibernate.hql.internal.HolderInstantiator.instantiate(HolderInstantiator.java:85)
17:18:58,262 ERROR [stderr] (default task-21) at org.hibernate.loader.custom.CustomLoader.getResultList(CustomLoader.java:430)
17:18:58,262 ERROR [stderr] (default task-21) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507)
17:18:58,262 ERROR [stderr] (default task-21) at org.hibernate.loader.Loader.list(Loader.java:2502)
17:18:58,263 ERROR [stderr] (default task-21) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:335)
17:18:58,263 ERROR [stderr] (default task-21) at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2200)
17:18:58,263 ERROR [stderr] (default task-21) at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1016)
17:18:58,264 ERROR [stderr] (default task-21) at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:152)
17:18:58,264 ERROR [stderr] (default task-21) at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414)
17:18:58,264 ERROR [stderr] (default task-21) at org.hibernate.query.Query.getResultList(Query.java:146)
17:18:58,265 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.dao.BaseDao.loadTransformedObjectWithNativeSQL(BaseDao.java:228)
17:18:58,265 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.dao.config.ConfigConfigDaoImpl.getModelQuestionaire(ConfigConfigDaoImpl.java:2415)
17:18:58,266 ERROR [stderr] (default task-21) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
17:18:58,267 ERROR [stderr] (default task-21) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
17:18:58,268 ERROR [stderr] (default task-21) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
17:18:58,268 ERROR [stderr] (default task-21) at java.lang.reflect.Method.invoke(Method.java:498)
17:18:58,268 ERROR [stderr] (default task-21) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338)
17:18:58,269 ERROR [stderr] (default task-21) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
17:18:58,269 ERROR [stderr] (default task-21) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
17:18:58,270 ERROR [stderr] (default task-21) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
17:18:58,271 ERROR [stderr] (default task-21) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
17:18:58,271 ERROR [stderr] (default task-21) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
17:18:58,271 ERROR [stderr] (default task-21) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
17:18:58,271 ERROR [stderr] (default task-21) at com.sun.proxy.$Proxy110.getModelQuestionaire(Unknown Source)
17:18:58,272 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.services.config.ModelConfigServiceImpl.getModelQuestionaire(ModelConfigServiceImpl.java:301)
17:18:58,272 ERROR [stderr] (default task-21) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
17:18:58,273 ERROR [stderr] (default task-21) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
17:18:58,274 ERROR [stderr] (default task-21) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
17:18:58,274 ERROR [stderr] (default task-21) at java.lang.reflect.Method.invoke(Method.java:498)
17:18:58,274 ERROR [stderr] (default task-21) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338)
17:18:58,275 ERROR [stderr] (default task-21) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:206)
17:18:58,276 ERROR [stderr] (default task-21) at com.sun.proxy.$Proxy113.getModelQuestionaire(Unknown Source)
17:18:58,276 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.services.config.ModelConfigSvcImpl.getModelQuestionaire(ModelConfigSvcImpl.java:1872)
17:18:58,276 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.cmd.config.model.LoadModelQuestionaireCmd.perform(LoadModelQuestionaireCmd.java:325)
17:18:58,278 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.cmd.config.model.LoadModelQuestionaireCmd$$FastClassBySpringCGLIB$$346f0b5b.invoke(<generated>)
17:18:58,278 ERROR [stderr] (default task-21) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
17:18:58,278 ERROR [stderr] (default task-21) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:747)
17:18:58,278 ERROR [stderr] (default task-21) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
17:18:58,279 ERROR [stderr] (default task-21) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
17:18:58,279 ERROR [stderr] (default task-21) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
17:18:58,279 ERROR [stderr] (default task-21) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
17:18:58,279 ERROR [stderr] (default task-21) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
17:18:58,279 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.cmd.config.model.LoadModelQuestionaireCmd$$EnhancerBySpringCGLIB$$7bf6e8d7.perform(<generated>)
17:18:58,280 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.controller.config.model.ModelController.modifyModelOpenModel(ModelController.java:438)
17:18:58,280 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.controller.config.model.ModelController$$FastClassBySpringCGLIB$$9a0181ee.invoke(<generated>)
17:18:58,280 ERROR [stderr] (default task-21) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
17:18:58,280 ERROR [stderr] (default task-21) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:747)
17:18:58,280 ERROR [stderr] (default task-21) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
17:18:58,281 ERROR [stderr] (default task-21) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)
17:18:58,281 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.aspect.ExceptionAspectHandler.handleControllerExceptionsWithAroundReturnString(ExceptionAspectHandler.java:45)
17:18:58,281 ERROR [stderr] (default task-21) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
17:18:58,281 ERROR [stderr] (default task-21) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
17:18:58,282 ERROR [stderr] (default task-21) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
17:18:58,282 ERROR [stderr] (default task-21) at java.lang.reflect.Method.invoke(Method.java:498)
17:18:58,282 ERROR [stderr] (default task-21) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:643)
17:18:58,282 ERROR [stderr] (default task-21) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:632)
17:18:58,283 ERROR [stderr] (default task-21) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
17:18:58,283 ERROR [stderr] (default task-21) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
17:18:58,283 ERROR [stderr] (default task-21) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
17:18:58,283 ERROR [stderr] (default task-21) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
17:18:58,284 ERROR [stderr] (default task-21) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
17:18:58,284 ERROR [stderr] (default task-21) at com.gee.gecs.cosmos.controller.config.model.ModelController$$EnhancerBySpringCGLIB$$2add3965.modifyModelOpenModel(<generated>)
17:18:58,285 ERROR [stderr] (default task-21) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
17:18:58,285 ERROR [stderr] (default task-21) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
17:18:58,285 ERROR [stderr] (default task-21) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
17:18:58,285 ERROR [stderr] (default task-21) at java.lang.reflect.Method.invoke(Method.java:498)
17:18:58,285 ERROR [stderr] (default task-21) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
17:18:58,286 ERROR [stderr] (default task-21) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
17:18:58,286 ERROR [stderr] (default task-21) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
17:18:58,286 ERROR [stderr] (default task-21) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:871)
17:18:58,286 ERROR [stderr] (default task-21) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:777)
17:18:58,286 ERROR [stderr] (default task-21) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
17:18:58,287 ERROR [stderr] (default task-21) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
17:18:58,287 ERROR [stderr] (default task-21) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
17:18:58,287 ERROR [stderr] (default task-21) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
17:18:58,287 ERROR [stderr] (default task-21) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
17:18:58,288 ERROR [stderr] (default task-21) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
17:18:58,289 ERROR [stderr] (default task-21) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
17:18:58,290 ERROR [stderr] (default task-21) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
17:18:58,290 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
17:18:58,290 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
17:18:58,290 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
17:18:58,291 ERROR [stderr] (default task-21) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
17:18:58,291 ERROR [stderr] (default task-21) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
17:18:58,294 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
17:18:58,295 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
17:18:58,295 ERROR [stderr] (default task-21) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
17:18:58,296 ERROR [stderr] (default task-21) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
17:18:58,297 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
17:18:58,297 ERROR [stderr] (default task-21) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
17:18:58,297 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
17:18:58,298 ERROR [stderr] (default task-21) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
17:18:58,298 ERROR [stderr] (default task-21) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
17:18:58,298 ERROR [stderr] (default task-21) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
17:18:58,298 ERROR [stderr] (default task-21) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
17:18:58,298 ERROR [stderr] (default task-21) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
17:18:58,299 ERROR [stderr] (default task-21) at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
17:18:58,299 ERROR [stderr] (default task-21) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
17:18:58,299 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
17:18:58,299 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
17:18:58,299 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
17:18:58,299 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
17:18:58,300 ERROR [stderr] (default task-21) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
17:18:58,300 ERROR [stderr] (default task-21) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
17:18:58,300 ERROR [stderr] (default task-21) at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
17:18:58,300 ERROR [stderr] (default task-21) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
17:18:58,300 ERROR [stderr] (default task-21) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
17:18:58,300 ERROR [stderr] (default task-21) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
17:18:58,301 ERROR [stderr] (default task-21) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
17:18:58,306 ERROR [stderr] (default task-21) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
17:18:58,307 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
17:18:58,308 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
17:18:58,308 ERROR [stderr] (default task-21) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
17:18:58,308 ERROR [stderr] (default task-21) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
17:18:58,309 ERROR [stderr] (default task-21) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
17:18:58,309 ERROR [stderr] (default task-21) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
17:18:58,309 ERROR [stderr] (default task-21) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
17:18:58,309 ERROR [stderr] (default task-21) at java.lang.Thread.run(Thread.java:748)
17:18:58,311 ERROR [com.gee.gecs.cosmos.aspect.ICAMExceptionHandler] (default task-21) A UndeclaredThrowableException has occured in the application: java.lang.reflect.UndeclaredThrowableException
at com.gee.gecs.cosmos.controller.config.model.ModelController$$EnhancerBySpringCGLIB$$2add3965.modifyModelOpenModel(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:871)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:777)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitia
如果将List
更改为List<?>
,则会出现编译时错误:
Type mismatch: cannot convert from List<capture#55-of ?> to
List<ModelData>
解决此问题的最佳方法是什么。我有多种调用此方法的方法
public List loadTransformedObjectWithNativeSQL(String paramString, Map paramMap, Object[] paramArrayOfObject, Class paramClass)
{
Object localObject = null;
NativeQuery localNativeQuery = this.sessionFactory.getCurrentSession().createNativeQuery(paramString);
Iterator localIterator = paramMap.entrySet().iterator();
while (localIterator.hasNext())
{
Map.Entry localEntry = (Map.Entry)localIterator.next();
String str = (String)localEntry.getKey();
Type localType = (Type)localEntry.getValue();
localNativeQuery.addScalar(str, localType);
}
for (int i = 1; i <= paramArrayOfObject.length; i++) {
localNativeQuery.setParameter(i, paramArrayOfObject[(i - 1)]);
}
System.out.println("*************SQLQuery[OBJ]*****************" +localNativeQuery.getQueryString());
localNativeQuery.setResultTransformer(Transformers.aliasToBean(paramClass));
return localNativeQuery.getResultList();
}
答案 0 :(得分:0)
复制列表。这样做将确保列表的类型安全,因为如果不正确,强制转换会在运行时引发异常:
List<?> untypedData = (List<?>)
loadTransformedObjectWithNativeSQL(sql, map, values, ModelData.class);
List<ModelData> modelData = new ArrayList<>(untypedData.size());
for (Object datum : untypedData) {
modelData.add((ModelData) datum);
}
return modelData;
这似乎很浪费,但不是。您只复制参考。如果我们悲观地认为引用是256个字节(可能小于该字节),则复制4,000个字节将占用1 MB的内存。
答案 1 :(得分:0)
问题已解决。.在我的代码中,ModelData类项目-问卷和查询结果列之间的映射存在问题。一旦解决,该错误就消失了。