我有一个用列char定义的表,我定义了一个查询来返回该列。现在,当db表中的数据对于特定条件为null时,它会给我错误:
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)
2条答案
按热度按时间2ledvvac1#
使用
Character
代替char
。当你的查询返回NULL时,你知道Java中的基本类型不能保存空值。所以,使用像int -> Integer, float -> Float, char -> Character
这样的类型的Object。或者,如果你真的需要使用原语,把你的方法放在try-catch块中,来处理这个问题。
yruzcnhs2#
确保你使用了正确的仓库名称,在我的例子中,我需要通过电子邮件获取用户:
错误:
更正:
JPA无法解释使用“find”但使用“exists”的布尔查询