hibernate:count查询

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

		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;


你可能感兴趣的:(java)