我有这个问题:
[{\"DatumPoruke\":\"2015-12-14T12:10:20.841Z\",\"Tekst\":\"posao 1\",\"FromUserid\":\"user\",\"ToUserid\":\"driver\",\"ChatId\":\"1\"},{\"DatumPoruke\":\"2015-12-14T12:10:24.077Z\",\"Tekst\":\"Prihvaceno\",\"FromUserid\":\"driver\",\"ToUserid\":\"user\",\"ChatId\":\"1\"}]
哪个不起作用,因为hibernate会忽略em.createQuery("select new SomeDto(some.name, " +
"(select max(other.weight) from Other other where other.someId = some.id) as otherWeight" +
") from Some some order by otherWeight")
.getResultList();
而只是生成as otherWeight
。
这种as col_1_0_
查询是否有办法获取列的别名?
如果没有:我怎么能做这样的查询(将查询结果映射到DTO构造函数)?
答案 0 :(得分:0)
您可以尝试以下查询,该查询也应该更快:
select new SomeDto(some.name, max(other.weight))
from Other other right outer join other.some some
group by some.id, some.name
order by max(other.weight)
如果您还没有Other
到Some
,则需要引入多对一(或一对一)关联。