hibernate hql getMaxVersion
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.
精彩评论