0
我有表,跟随着属性使用Hibernate
h_id,姓名,检索表最大值.....
,我想回发生在表中最大编号。
我使用
"select max(h.h_id) from Hospital h"
会抛出
org.hibernate.exception.ConstraintViolationException:无法 执行语句
什么riht办法做到这一点?
//编辑,代码
public static Integer getHospitalId(){
List<Integer> ids = null;
try {
Query q = session.createQuery ("select max(h.h_id) from Hospital h");
ids = (List<Integer>)q.list();
} catch (Exception e) {
e.printStackTrace();
}
if(ids!= null)
return ids.get(0) + 1;
return new Integer(0);
}
}
你确定这是导致限制冲突查询?也许如果你分享了一些代码和完整的堆栈跟踪,你可以得到更好的答案。 –
添加代码示例 – Dingo
为什么使用'list()'? –