Что является альтернативой для объявления необработанного типа List - PullRequest
0 голосов
/ 18 мая 2019

У меня есть фрагмент кода, в котором я вызываю метод dao и возвращаю список объектов diff в зависимости от результата вызова. Вызывающий метод возвращает список в зависимости от результата запроса. Вызываемый метод имеет объявление в rawtype, как показано ниже. Код компилируется нормально, но при определенных проблемах возникает ошибка во время выполнения.

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();
  }

Ответы [ 2 ]

0 голосов
/ 21 мая 2019

Проблема решена .. В моем коде была проблема с отображением между элементами класса ModelData - квестинером и столбцами результата запроса. Как только это исправлено, эта ошибка исчезнет.

0 голосов
/ 18 мая 2019

Скопируйте список.Это гарантирует безопасность типов списка, так как приведение вызывает исключение во время выполнения, если оно неверно:

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 байт (вероятно, она меньше), при копировании 4000 из них потребуется 1 МБ памяти.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...