【发布时间】:2012-01-30 13:30:45
【问题描述】:
我试图只获取返回的行数,而不是表中的所有结果。
我看到可以这样做:
( (Integer) session.createQuery("select count(*) from ....").iterate().next() ).intValue()
但是当试图以整数格式存储这个查询时(它说不能从Query to Integer转换)
我正在使用动态查询,其中值将在查询下方提及
theQuery = "select count(*) from THM as thm " +
"join thm.TMC as tmc " +
"join tmc.TIMCC as timcc " +
"where thm.Qid = :Qid and thm.Cv = :Cv and timcc.Did = :Did and timcc.Cv= :Cv";
Query query = session.createQuery(theQuery);
query.setInteger("Qid", Integer.parseInt(Qid));
query.setInteger("Did", Did);
query.setInteger("Cv",cV);
现在,我如何在不使用 list.size 而是直接从查询中获取通过在变量中使用 Hibernate 查询返回的所有行的计数?
【问题讨论】:
标签: java database hibernate hql