-->
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.  [ 3 posts ] 
Author Message
 Post subject: setFirstResult and setMaxResults for createSQLQuery
PostPosted: Fri Jul 30, 2010 12:16 pm 
Newbie

Joined: Fri Jul 30, 2010 11:14 am
Posts: 2
Hi all,

I want to replace some code which was using the Hibernate Criteria API with a SQL query. So instead of calling...

Code:
List results = getHibernateTemplate().findByCriteria(myCriteria);


I now have...

Code:
List results = getSession().createSQLQuery(query).list();


The problem is that the old code also calls Criteria's setFirstResult and setMaxResults methods. Are there any equivalents for these when using createSQLQuery?

Thanks in advance for any help,
Jehan


Top
 Profile  
 
 Post subject: Re: setFirstResult and setMaxResults for createSQLQuery
PostPosted: Fri Jul 30, 2010 12:16 pm 
Newbie

Joined: Fri Jul 30, 2010 11:14 am
Posts: 2
I found that the Hibernate Query objects does have these methods, but for some reason when I used them my ResultSet went from being composed of Integers to being composed or Object arrays. Anyone know why this happened? Weird.


Top
 Profile  
 
 Post subject: Re: setFirstResult and setMaxResults for createSQLQuery
PostPosted: Fri Jul 30, 2010 12:23 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
if you use a plain SQL query you have to implement your pagination; pagination is a complex topic handled in different ways depending on the situation and database specifics: if you write your own free-form SQL then hibernate can't append some statement to implement pagination: the whole point of using plain SQL is that you want to write the query yourself and avoid Hibernate's help.
Maybe using an HQL query is better suited to convert the criteria?

_________________
Sanne
http://in.relation.to/


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