-->
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.  [ 6 posts ] 
Author Message
 Post subject: Pagination: ScrollableResults vs Criteria (record count)
PostPosted: Mon Mar 13, 2006 4:53 pm 
Beginner
Beginner

Joined: Wed Feb 15, 2006 2:51 pm
Posts: 20
Hello I am using Orcacle database. I am trying to write some pagination functionlity.
Where i can get the total number of records + selecet records page by page.

I been searching through the post and found that it can be done both ways

1)
ScrollableResults:

ScrollableResults people = query.scroll();
people.last();
totalResults = people.getRowNumber() + 1;
setRowNumber(initialRow);
scroll(maxNbRows);


2)
Criteria

criteria.setFirstResult( initialRow );
criteria.setMaxResults(maxNbRows);
results = criteria.list();
criteria.setProjection(Projections.rowCount());
Integer result = (Integer) criteria.uniqueResult();
totalResults = result.intValue();


It seems to be more work when i want to deal with collections and records when using ScrollableResults comparing to Criteria class where i can get a list of objects in a collection. At the same time, it seems that i am writing more SQL statements when using the criteria.

If any expert can give me some advantages/disadventages on what would be better to go to set up pagination that would be great.

Thank you!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 1:54 pm 
Beginner
Beginner

Joined: Wed Feb 15, 2006 2:51 pm
Posts: 20
bump


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 2:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If your posting (or a question you are referring to) was not answered by anybody, the possible reasons are:

- http://www.hibernate.org/ForumMailingli ... AskForHelp
- You did not submit enough information
- Nobody knows the answer or has the free time to answer

What you can do now:

- Do the things listed in After Posting
- Add missing and/or more information
- Consider commercial support for guaranteed expert response times

This is a high-traffic forum run by volunteers with hundreds of postings made every day. The community works because people try to help others in their free time. Nobody is paid for this service or has to pay.

You should not expect a timely response and you should not rely on a public community forum for critical cases.

All community members should respect the rules of this forum and treat others like they would prefer to be treated.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 4:09 pm 
Beginner
Beginner

Joined: Wed Feb 15, 2006 2:51 pm
Posts: 20
Sorry and got ya!!


Top
 Profile  
 
 Post subject: Record count with named query
PostPosted: Wed Mar 15, 2006 7:18 pm 
Beginner
Beginner

Joined: Wed Feb 15, 2006 2:51 pm
Posts: 20
Hello,

Is there an easy way of counting records that where selected in a named query, before i get the results in a collection??

I want to count the number of records before I apply my paging, using
setFirstResult
setMaxResults



I know that I can do it with criteria, buy using
criteria.setProjection(Projections.rowCount());

thank you


Top
 Profile  
 
 Post subject: Re: Record count with named query
PostPosted: Fri Mar 17, 2006 4:09 pm 
Newbie

Joined: Fri Mar 17, 2006 3:59 pm
Posts: 1
golly97 wrote:
Hello,

Is there an easy way of counting records that where selected in a named query, before i get the results in a collection??

I want to count the number of records before I apply my paging, using
setFirstResult
setMaxResults



I know that I can do it with criteria, buy using
criteria.setProjection(Projections.rowCount());

thank you


Hello,
I'm also new to Hibernate and I dont know if this is the correct approach but what I have done in this case is:

Add a new attribute to POJO class that is not associated with any table field, and in this case Hibernate will not try to save it to back-end.

Sample:
Sample for Issue xml definition.
...
<property name="articlesNo" type="long"
formula="( SELECT COUNT(A.id_Article) FROM tblArticles A WHERE A.id_Issue=id_Issue )"/>
...

<set name="articlesVO" inverse="true" lazy="true" cascade="all" order-by="position ASC">
<key column="id_Issue" not-null="true"/>
<one-to-many class="...ArticleVO"/>
</set>
....

Hope this help
OO


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