hibernate:count查询

来源:互联网 发布:传统颜色名称 知乎 编辑:程序博客网 时间:2024/06/15 11:58

用hibernate做count(*)查询,结果集需用createSQLQuery()

<span style="white-space:pre"></span>String sql="SELECT COUNT(1) "+ " from Test_Classinfo a,Test_Student b,TestStudent_Question c "+ " where a.testId=b.testId "+ " and b.id=c.testStudentId "+ " and c.userAnswer!=NULL "+ " and a.classInfoId='"+classinfoId+"'"+ " and a.testId='"+testId+"'";Query query = this.getCurrentSession().createSQLQuery(sql);int count=((Number)query.uniqueResult()).intValue();return count;


0 0