• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

how to get limited record in hql?

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI every body i am using this query to get single value from data base but it is returning multiple values.I know setFirstResult and setMaxResult but except that can we use other things directly in hql.

select count(S.humanID) from Human S,Animal W WHERE S.humanID=W.animalID group by S.humanID order by count(S.humanID) desc limit 0,1
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is that limit keyword about? I don't see it in the HQL documentation.
 
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you want to use anything in the HQL query. The setFirstResult and setMaxResult method handle this nicely. Moreover the limit clause that you are referring to, is database specific. So it may work in MySql but not in Oracle or some other DBMS. So it is safer to use the method provided by Hibernate...
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

lokesh pattajoshi wrote:HI every body i am using this query to get single value from data base but it is returning multiple values.I know setFirstResult and setMaxResult but except that can we use other things directly in hql.

select count(S.humanID) from Human S,Animal W WHERE S.humanID=W.animalID group by S.humanID order by count(S.humanID) desc limit 0,1



There is no database independant way to express the FirstResult/MaxResult semantic in SQL. So there is no way you can do it via HQL. setFirstResult/setMaxResults will be translated into LIMIT x,y for MySQL Dialect. But the sql for other databases is totally different (e.g. "fetch first x rows only" for DB2).

If you except a single row result but you get mulitple rows than you should re-think your statement. It might be wrong.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic