我想用Hibernate Criteria实现以下SQL查询:
select abc_id, count(*) from boa_rep_deed where sync_system = ? And hook_id = ? group by abc_id order by abc_id
我试过的是这个...
List<teedObject> hytlow = null;
Criteria criteria = session.createCriteria(teedObject.class);
criteria.add(Restrictions.ne("abcID ", abcID));
criteria.add(Restrictions.eq("syncSystem", syncSystem));
criteria.add(Restrictions.eq("hookId", hookId));
hytlow = criteria.list();
现在我的问题是我也有相应的pojo,如下所示..
class teedObject
{
private long abcID ;
private String syncSystem ;
private String hookId;
//and consisits other properties and setters and getters
}
现在我希望我的标准只获取某些列,以便使对象更新,我必须使用标准中的投影,你能否告诉我如何在我的情况下使用投影,以便只获取某些coulmns
答案 0 :(得分:0)
标准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();