开发者

hibernate hql getMaxVersion

开发者 https://www.devze.com 2023-01-04 10:43 出处:网络
I have a table with the following structure: ReportId Version Title ..... I want to use HQL to fetch the newest version of the report by id. Would the following query work?

I have a table with the following structure:

ReportId

Version

Title

.....

I want to use HQL to fetch the newest version of the report by id. Would the following query work?

from Report where reportId = :reportId and version = (select max(version) from Report where reportId = :reportId)

Is it possible to retrieve the row with the maximum version without using a sub-select? Is the above sub-select even legal in h开发者_如何学Cibernate HQL?


Try this query:

    from Report where reportId = :reportId order by version desc 

with setMaxResults=1


You can order by version and use setMaxResults on the query (set it to 1). As for the other question, subselects like this are legal in hql.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号