【问题标题】:using projections to fetch certain columns through criteria使用投影通过条件获取某些列
【发布时间】:2014-02-16 10:04:07
【问题描述】:

我想用 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

}

现在我希望我的标准仅获取某些列以使对象更轻因此我必须使用标准中的投影,您能否建议在我的情况下如何使用投影以仅获取某些列

【问题讨论】:

    标签: hibernate criteria


    【解决方案1】:

    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();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      • 2019-01-07
      • 2015-05-02
      相关资源
      最近更新 更多