Hibernate version: 5.2
I am trying to use subqueries to do, and use setMaxResults(int).
session.createQuery(
"FROM ( SELECT * FROM tickets ORDER BY id DESC limit 3) sub ORDER BY id ASC"
);
However, HQL subqueries can occur only in the select or where clauses, and limit can't be used in hibernate.
How can I do it in hibernate?
Update - To make it clear
For eg, there are 10 data entries from id=1 to id=10.
I want to select last 3 data in ascending order of id by only one query + without further data processing.
The result from db would be id=8 to id=10
Thank You.