在用hibernate进行查询的时候,发生了如下异常:
aop.AopInvocationException: null return value from advice does not match primitive return type for
here is the DAO interface:
@Query(value = “SELECT indexed FROM “+ GlobalConsts.INTELLIF_STATIC + “.” +GlobalConsts.T_NAME_OTHER_DETAIL
+” WHERE id = :id”, nativeQuery = true)
int findLast(@Param(“id”)long id);
如果该id在数据库中不存在,就会返回null,报出异常。
这里可以让返回的值变为包装类,它仅仅只会返回null,而不会报异常。
@Query(value = “SELECT indexed FROM “+ GlobalConsts.INTELLIF_STATIC + “.” +GlobalConsts.T_NAME_OTHER_DETAIL
+” WHERE id = :id”, nativeQuery = true)
Integer findLast(@Param(“id”)long id);