-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: HQL Query - Please help me
PostPosted: Fri Mar 26, 2010 11:02 am 
Newbie

Joined: Sat Oct 24, 2009 2:41 pm
Posts: 4
Hi,
I am new to Hibernate. I need to display last 10 records from table "users". I can write SQL query like this SELECT * FROM users ORDER BY id DESC LIMIT 10

Can any one help me to write same in HQL. I tried like this "from Users ORDER BY id DESC LIMIT 10" , but its displaying all records.

Please help me to solve this issue.

Thanks in advance
--
Vini


Top
 Profile  
 
 Post subject: Re: HQL Query - Please help me
PostPosted: Fri Mar 26, 2010 12:42 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The Query object has a setMaxResults() method. Use that instead of LIMIT 10 and it should work.


Top
 Profile  
 
 Post subject: Re: HQL Query - Please help me
PostPosted: Fri Mar 26, 2010 2:47 pm 
Newbie

Joined: Sat Oct 24, 2009 2:41 pm
Posts: 4
Thanks a lot. Its working fine now....

nordborg wrote:
The Query object has a setMaxResults() method. Use that instead of LIMIT 10 and it should work.


Top
 Profile  
 
 Post subject: Re: HQL Query - Please help me
PostPosted: Sun Mar 28, 2010 8:52 am 
Newbie

Joined: Sun Mar 28, 2010 8:41 am
Posts: 4
Hi

If you are using Detached Criteria you an use setMaxResults() method

eg: DetachedCriteria criteria = DetachedCriteria.forClass("aVO.class");
criteria.addOrder(Order.set("desc"));
criteria.setMaxResults(10);

Regards
Sidharth Sharma


Top
 Profile  
 
 Post subject: Re: HQL Query - Please help me
PostPosted: Sun Mar 28, 2010 12:33 pm 
Newbie

Joined: Sat Oct 24, 2009 2:41 pm
Posts: 4
Thank you Sidharth,

sidharth1985 wrote:
Hi

If you are using Detached Criteria you an use setMaxResults() method

eg: DetachedCriteria criteria = DetachedCriteria.forClass("aVO.class");
criteria.addOrder(Order.set("desc"));
criteria.setMaxResults(10);

Regards
Sidharth Sharma


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.