正文
使用Spring Data JPA查询时,报result returns more than one elements异常
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
public static <T> T get(String hql, Class<T> t) {
EntityManager em = getFactory().createEntityManager();
try {
return em.createQuery(hql, t).getSingleResult();
} catch (NoResultException e) {
e.printStackTrace();
return null;
} finally {
em.close();
}
}
getSingleResult();
结果多于一个 就报异常