-->
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 to get 10 records
PostPosted: Tue Nov 18, 2008 7:39 pm 
Newbie

Joined: Tue Nov 18, 2008 3:42 pm
Posts: 3
Hi,

How to write hql query to get 10 records order by date?

String query = "from Registration as registration ";
Registration registration = null;
List list = this.getHibernateTemplate().find(query);


how to change this code to get 10 records alone?

thanks,
Aarthy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2008 8:49 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
String query = "from Registration as registration ";
Session session=this.getHibernateTemplate().getSession();
Query query=session.createQuery(query);
query.setFirstResult(0);
query.setMaxResults(10);
List list = query.list();

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 1:06 am 
Newbie

Joined: Tue Nov 18, 2008 3:42 pm
Posts: 3
Hi gonzao_diaz,

I tried your code.
I am getting this error.

The method getSession() is not visible from hibernate template.

pls help.

Thanks,
Aarthy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 3:28 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
True...
The problem is, there are no such first-maxrows methods in the HibernateTemplate.

If you can, don't use HibernateTemplate anymore (it is obsolete), and try instead to use contextual sessions directly.

A good simple example of the new Hibernate-Spring configuration is given here

http://hibernar.org/articulos_en/spring ... xample.php

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 3:57 am 
Newbie

Joined: Wed Nov 19, 2008 3:13 am
Posts: 4
s i too i felt some issues with Hibernate Templates

-----------------
vinora


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.