org.hibernate.NonUniqueResultException: query 没有返回唯一结果:2?
我的DAO中有以下代码:
String sql = "SELECT COUNT(*) FROM CustomerData " +
"WHERE custId = :custId AND deptId = :deptId";
Query query = session.createQuery(sql);
query.setParameter("custId", custId);
query.setParameter("deptId", deptId);
long count = (long) query.uniqueResult(); // ERROR THROWN HERE
休眠在标记的行处抛出以下异常:
org.hibernate.NonUniqueResultException: query 未返回唯一结果:
我不确定发生了什么,因为总是只返回一行。count(*)
此外,当我直接在db上运行此查询时,它将结果返回为1。那么问题出在哪里呢?