简体   繁体   English

在执行本机JPA /休眠查询之后,按结果列排序

[英]ORDER BY a result column AFTER a native JPA/Hibernate query has executed

Say I have the following native SQL: 说我有以下本地SQL:

SELECT a, b, c + d AS cd
FROM stuff

I know it's easy to just sort it using order by . 我知道使用order by对其进行排序很容易。

I was just wondering if JPA/Hibernate has a way to specify ordering AFTER the query executes and the results have returned, eg for sorting by the cd column. 我只是想知道JPA / Hibernate是否可以在查询执行后返回结果后指定顺序(例如,按cd列排序)。 Basically something like a Comparator (except it's built into the ORM). 基本上像比较器(除了它内置在ORM中)。

not that i know of. 从来没听说过。 but i would say that your db is usually much more efficient at sorting the data than any code you would write. 但是我要说的是,您的数据库在排序数据方面通常比您编写的任何代码都高效得多。 i would stuck with letting the db do i. 我会坚持让DB做我。

JPA offers "ORDER BY" support, I'm using it. JPA提供了“ ORDER BY”支持,我正在使用它。 You can use following syntax. 您可以使用以下语法。

SELECT a, b, c + d AS cd FROM stuff ORDER BY cd [DESC/ASC]; 从东西中按CD [DESC / ASC]选择a,b,c + d AS cd;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM