0

In oracle 12c we can use fetch first clause to select first n rows of a table.
Is there equivalent clause in hibernate to Oracle 12c's fetch first ... clause?
example of fetch first:

select *
  from tbl_order t
 order by t.orderDate desc
 fetch first 1 rows only;   

Note that i don't want to use rownum clause.
I want a solution in HQL itself not in hibernate methods like setMaxResults().

Ali Sohrabi
  • 134
  • 2
  • 12
  • sounds to me like a synonym for limit clause. you can achieve that with `query.setMaxResults()` – Sharon Ben Asher Jul 02 '18 at 11:14
  • @dasblinkenlight, the question that you pointed to it as duplicate is for 2009. there are many versions of hibernate released after that date. note that my question is about a solution in hql not in hibernate methods. – Ali Sohrabi Jul 02 '18 at 11:30
  • @AliSohrabi The marked answer talks specifically about HQL support of limit, and says that it was never planned to be supported (hibernate-2 supported it almost by omission). The question has pretty high "traffic", so once it becomes outdated, usually someone suggests and approves an edit. [Current version of HQL manual](https://docs.jboss.org/hibernate/orm/3.5/reference/en-US/html/queryhql.html) does not mention limits, though. – Sergey Kalinichenko Jul 02 '18 at 12:12
  • Ok, you are right. Thanks. – Ali Sohrabi Jul 02 '18 at 13:18

0 Answers0