org.springframework.aop.AopInvocationException:建议的空返回值与以下类型的原始返回类型不匹配:public abstract char

时间:2019-06-07 16:07:56

标签: java jpa

我有一个用char列定义的表,我定义了一个repo 查询以返回该列。现在,当数据库表中的数据为空时 对于特定条件,它会给我错误:

org.springframework.aop.AopInvocationException: Null return value from 
advice does not match primitive return type for: public abstract char

下面是代码段:

    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.data.jpa.repository.Query;
    import org.springframework.data.repository.query.Param;

    import com.marriott.sup.beans.StepWorkflow;

    public interface flowRepo extends JpaRepository<StepWorkflow, Long> {

        @Query(
                value = "SELECT s.status FROM flow s WHERE s.XREFID 
     = :xrefId order by "
                + "s.Datestarted desc limit 1",
                nativeQuery = true)
        public char findLatestSts(@Param("xrefId") Long xrefId);

    }

    public class flowService {

        public static char INPROGRESS = 'P';
        public static char SUCCESS = 'S';
        public static char ERROR = 'E';
        public static char NOTSTARTED = 'N';

        @Autowired
        private flowRepo Fl;

        /*some basic code in between and then i am trying to call the 
      function 
      defined in repo and assign it to a character variable
    */

    Sts = Fl.findLatestSts(xrefId);
    }

我需要它不会引发错误,而是为null分配一些默认值。在解决该问题方面需要帮助。

org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract char org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:226) at com.sun.proxy.$Proxy108.findLatestSts(Unknown Source) at com.marriott.sup.service.StepWorkflowService.getserverStepstatus(StepWorkflowService.java:79) at com.marriott.sup.web.SampleRestController.getServerStepStatus(SampleRestController.java:91) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) 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:892) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)

1 个答案:

答案 0 :(得分:0)

尝试使用Character代替char。在某些情况下,查询将返回NULL,并且您知道Java中的原始类型无法在其中保存Null。因此,请使用int -> Integer, float -> Float, char -> Character之类的对象。

或者,如果您确实需要使用原始函数,请将您的方法放在try-catch块中,以解决该问题。