1
Select top 1 from <tablename>

what is hql query for the above ?

Franz
  • 11,143
  • 8
  • 47
  • 69
sateesh
  • 11
  • 1

3 Answers3

5

Just write a normal query, ans use "SetMaxResult" to limit your results.

I.e.

return  getSession().createQuery("from items order by id asc")
            .setMaxResults(1)
            .list();
Marcos Placona
  • 21,108
  • 11
  • 66
  • 93
2

It seems you must use the setMaxResults() method.

See for example this question+answer : How do you do a limit query in HQL

Community
  • 1
  • 1
Pascal MARTIN
  • 385,748
  • 76
  • 642
  • 654
1

You'll probably want to use the setMaxResults of the Query Object.

To my knowledge, HQL does not support top or limit.

tschaible
  • 7,550
  • 1
  • 29
  • 33