我想用Hibernate HQL实现以下SQL查询:
select abc_id, count(*) from boa_rep_deed where sync_system = ? And hook_id = ? group by abc_id order by abc_id
现在我的问题是我也有相应的pojo,如下所示..
class teedObject{
private long abcID ;
private String syncSystem ;
private String hookId;
//and consisits other properties and setters and getters
}
我已实施以下标准..
Criteria cr = session.createCriteria(teedObject.class);
cr.add(Restrictions.eq("syncSystem", syncSystem));
cr.add(Restrictions.eq("hookId", hookId));
cr.addOrder(Order.asc("abcID"));
cr.add(Projections.groupProperty("abcID")));
cr.setProjection(Projections.rowCount());
hytlow = cr.list();
现在请告知我如何使用HQL实现相同目的 伙计们请指教
答案 0 :(得分:0)
未经测试,但我想:
select x.abcId, count(x)
from teedObject as x
where x.syncSystem = :syncSystemParam And x.hookId = :hookIdParam
group by x.abcId
order by x.abcId
HQL通常就像SQL一样,而列被属性和带有类的表替换,对应于映射。