我需要按照最大字段«timeStop»减去最小字段«timeStart»对我的分组对象进行排序。像这样的东西:
ProjectionList projList2 = Projections.projectionList();
projList2.add(Projections.alias(Projections.max("timeStop") - Projections.min("timeStop"), "tim"));//Compilation error
Criteria criteria = sess.createCriteria(Call.class);
criteria.addOrder(up ? Order.asc("tim") : Order.desc("tim"));
我该如何实现?
答案 0 :(得分:0)
使用sqlProjection
Projections.projectionList()
.add(Projections.sqlProjection("MAX(timeStop) - MIN(timeStop) AS tim",
new String[] { "tim" }, new Type[] {IntegerType.INSTANCE}));
休眠类型可以在org.hibernate.type包中找到