我只需要查询条目,而不需要里面的内容如果通过
createCriteria(xxx.class)
再返回list.size(),数据量大对数据库有压力请问有没有类似的select count(*) from xxx后面加条件的实现?能否将这段代码优化下??public Integer findCount(final Integer moduleId,final String rightName) throws DaoException {
return (Integer) hibernateTemplate.execute(new HibernateCallback(){ public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Criteria criteria=session.createCriteria(Right.class);
if(moduleId!=null){
criteria.add(Restrictions.eq("moduleId", moduleId));
}
if(rightName!=null && !rightName.equals("")){
criteria.add(Restrictions.eq("name",rightName));
}
return criteria.list().size();
}
});
}
createCriteria(xxx.class)
再返回list.size(),数据量大对数据库有压力请问有没有类似的select count(*) from xxx后面加条件的实现?能否将这段代码优化下??public Integer findCount(final Integer moduleId,final String rightName) throws DaoException {
return (Integer) hibernateTemplate.execute(new HibernateCallback(){ public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Criteria criteria=session.createCriteria(Right.class);
if(moduleId!=null){
criteria.add(Restrictions.eq("moduleId", moduleId));
}
if(rightName!=null && !rightName.equals("")){
criteria.add(Restrictions.eq("name",rightName));
}
return criteria.list().size();
}
});
}
再把值给它
count(*)
FROM NetworkCabinets nc,
ComputerLocation cl
WHERE nc.compLocaId=cl.id
and nc.compLocaId=:compLocaId
group by cl.name
dc.setProjection(Projections.projectionList().add(
Projections.count("id")));