No entity found for query

来源:互联网 发布:mysql存放路径 编辑:程序博客网 时间:2024/05/21 21:36
getSingleResult()
getSingleResult的源码有一句: @throws EntityNotFoundException if there is no result


查不到结果时,它是抛异常的,不会返回null.
解决方式,将异常捕捉
try{
Query query =this.getJpaTemplate().getEntityManager().createNativeQuery(sql,SmpRole.class);
obj = (SmpRole)query.getSingleResult();

    }catch(NoResultException e){
return null;
    }
0 0