我尝试对来自多选查询的一些自定义实体进行排序:
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
)。
但它只是没有排序..也没有错误。