对多选实体

时间:2016-11-02 14:44:50

标签: hibernate jpa spring-data-jpa hibernate-criteria criteria-api

我尝试对来自多选查询的一些自定义实体进行排序:

criteria = builder.createQuery();
chat = criteria.from(ChatModel.class);

criteria.multiselect(
   builder.construct(
      ChatInfo.class,
      chat.alias("chat"),
      builder.max(
          builder.coalesce(
              messages.get("created"),
              chat.get("created")
          )
      ).alias("lastActivity"))
  .groupBy(query.getChat())
  .orderBy(builder.asc(builder.literal("lastActivity")))

我需要实现的是按lastActivity字段对结果进行排序,该字段实际上是ChatInfo的attrbute(我也使用了alias)。

但它只是没有排序..也没有错误。

0 个答案:

没有答案