2

我有以下查询:

List results = getSession()
                .createCriteria(AppointmentSlot.class)
                .setProjection(
                        Projections.projectionList()
                                .add(Projections.min("startTime"))
                                .add(Projections.max("endTime"))
                                .add(Projections.groupProperty("clinicInfo"))
                                .add(Projections.groupProperty("staffInfo"))
                                .add(Projections.groupProperty("status"))
                                .add(Projections.groupProperty("dayId")))
                .list();

我想选择计算 和 差异的附加min("startTime")属性max("endTime")

更新

数据库中两列的样本值startTimeendTime

  1. 08:00:00, 08:15:00
  2. 08:15:00, 09:00:00
  3. 09:00:00, 09:15:00 ...

使用 Hibernate 怎么可能?

4

1 回答 1

2

尝试 sql 投影。就像是

List results = getSession()
                .createCriteria(AppointmentSlot.class, "apps")
                .setProjection(
                        Projections.projectionList()
                                .add(Projections.min("startTime").as("minStart"))
                                .add(Projections.max("endTime").as("maxTime"))
                                .add(Projections.groupProperty("clinicInfo"))
                                .add(Projections.groupProperty("staffInfo"))
                                .add(Projections.groupProperty("status"))
                                .add(Projections.groupProperty("dayId")))
                                .add(Projections.sqlProjection("(apps.minStart- apps.maxTime) as duration", new String[]{"duration"}, new org.hibernate.type.DateType[]{new org.hibernate.type.DateType()}),"duration")
                .list();
于 2013-10-10T18:34:53.950 回答