1
Select top 1 from <tablename>

what is hql query for the above ?

Franz
  • 11,353
  • 8
  • 48
  • 70
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,468
  • 11
  • 68
  • 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
  • 395,085
  • 80
  • 655
  • 663
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,635
  • 1
  • 31
  • 34