-->
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: Pagination. createcriteria and createQuery transformation
PostPosted: Thu Nov 17, 2005 3:39 pm 
Newbie

Joined: Thu Nov 17, 2005 3:22 pm
Posts: 1
HI All,

I am using Hibernate 3.0 and Oracle 8i. I am implementing pagination where the user would like to get the results as Google.
Previous 1 2 3 4 5 6 7 8 9 Next.

After reading the articles in the forum, the only solution was to use
the follwing code.
Query query = s.createQuery(queryString);
query.setFirstResult(pageNumber * resultsPerPage);
query.setMaxResults(resultsPerPage);
List queryResult = query.list();

The query build for our search component is complex as we have various joins across different tables and the so createQuery was decided over createCriteria.

Now to get the problem is row count which will facilitate to display Previous 1 2 3 4 5 6 7 8 9 Next.

But row count is only possible using
List results = session.createCriteria(Project.class)
.setProjection( Projections.rowCount() )
.add( Restrictions.eq("name", Name.getFirstName()) )
.list();

Is ther any way where I can convert query into criteria so as to so projections ? OR any other solution to the above mentioned problem.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 5:37 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Swarup,
First, if you have complex query and big tables i advice that use ScrollableResults instead
setFirstResult/setMaxResult - it is better for Oracle, because hibernate for your solution make
ugly query with rownum and it is slow when you have big tables, order clause etc

setFirstResult/setMaxResult is preffered way for databass like mysql, postgresql - they read complete query in memory and have LIMIT clause for out of memory

oracle use cursors always and ScrollableResults is better
then you can find row count (and it is quick) with
Code:
Query q = ...;
ScrollableResults scr = q.scroll();
scr.last();
count = scr.getRowNumber() + 1;


use last 10g rel 2 driver, too


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 6:03 am 
Beginner
Beginner

Joined: Wed Sep 17, 2003 10:43 am
Posts: 48
It there any answer to the original poster's question? I also use projections to count results of criteria[1] queries when building result pages but i havent found a way to do this using Query objects. Is it possible without actually loading the records from the database?

[1] http://forum.hibernate.org/viewtopic.php?t=951369


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.