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.  [ 2 posts ] 
Author Message
 Post subject: How to fetch top 5 records from database using hql
PostPosted: Mon Dec 01, 2008 12:35 am 
Newbie

Joined: Wed Oct 22, 2008 3:58 am
Posts: 4
Location: banaglore
hi all
i am using hibernate query language,i want latest 5records from data base,i am getting records according to date and time
but in view i want to diaplay only 5 records
can u tell any condition to put in query that will get only top 5records
i tried with limit,rownum conditions but i didn't get it
Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2008 2:22 am 
Newbie

Joined: Tue Nov 18, 2008 6:08 am
Posts: 14
you can do is

Code:
Session session = HibernetUtil.getSessionFactory().openSession();
Criteria criteria = session.createCriteria(ClassName.class);
criteria.setFirstResult(1);
criteria.setMaxResults(5);
List result = criteria.list();
session.close();


for imports take suggestions from your IDE.

this will give you top 5 results from your database
the query will be


Quote:
from table limit 1,5

assuming your top five records are saving system time
hope this helps


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.