使用条件查询在hibernate中按摘要排序

时间:2014-08-26 15:57:54

标签: java hibernate criteria

让我有以下crtieria查询:

int offset;
int count;
Date from;
Date to;

//Initialization of offset, count, from, to variables

ProjectionList projections = Projections.projectionList().
    add(Projections.groupProperty("date"));
addSumProjections(projections);
criteria.setProjection(projections);
criteria.setFirstResult(offset);
criteria.setMaxResults(count);
criteria.add(Restrictions.ge("date", from));
criteria.add(Restrictions.le("date", to));

private void addSumProjections(ProjectionList projections) {
    projections.add(Projections.sum("clickCount"))
        .add(Projections.sum("funPlayers"))
        .add(Projections.sum("funRounds"))
}

我想按照funRounds属性的总和对结果表进行排序,通过添加相应的投影add(Projections.sum("funPlayers"))来计算。是否可以使用条件查询来做到这一点?

0 个答案:

没有答案