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: How Could I do a Pagination by using NHibernate?
PostPosted: Tue Oct 30, 2007 9:42 pm 
Beginner
Beginner

Joined: Wed Aug 29, 2007 1:25 pm
Posts: 26
Location: Recife, PE, Brazil
Hello all,

I'm using SQL SERVER native SQL to do my paginations in my system.

There are just few SQL that I'm putting inside a Store procedure..

I would like to remove them from there because I dont want take care of SQL outside NHibernate /C# code.

How can I remove my SQL to do that?

Remember that the approach that I'm doing doesn't select all records in the database...

I select just those records that I need according to current page and the amount of records by page.

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 31, 2007 12:18 am 
Beginner
Beginner

Joined: Wed Aug 29, 2007 1:25 pm
Posts: 26
Location: Recife, PE, Brazil
people..

I took a look at internet by googling and I found something that does exactly what I was needing

Code:

            NHibernate.IQuery iQuery = NHibernateSessionModule.Session.GetNamedQuery("GetArticlesByProfile");

            iQuery.SetMaxResults(RecordsByPage);
iQuery.SetFirstResult(firstRercodToShow);



where "RecordsByPage" and "firstRercodToShow" are information came from aspx code behind page..


So, I dont know how NHibernate does the pagination yet

I dont know if it retrieves all records and just filters them or really does as should be...by retrieving just the ones that I have passed via parameter

but it works fine!

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 31, 2007 4:19 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
The answer is, it depends.

MySQL supports setting skipping records and setting max records to be retrieved, so NHibernate will only get those records as MySQL will skip the first records as requested.

On the other hand, SQL Server 2000 supports setting max records but doesn't support skipping to the first specified, so it can't skip the records like MySQL can. As a result NHibernate still gets the skipped records in the result set but just doesn't create objects from them.

It's done in the most efficient way possible given the technology it works with, but it will depend on your RDBMS.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 31, 2007 9:48 am 
Beginner
Beginner

Joined: Wed Aug 29, 2007 1:25 pm
Posts: 26
Location: Recife, PE, Brazil
exactly.

but there is a way to do that by using SQL SERVER that doesn't retrieve all records in the database.

it would be by using temp table in a Store Procedure where you could pass the current page and how many records you want to get.

In MySQL that would be so easy by using LIMIT, so NHibernate can do it easily as well

but I'm not sure if inside NHibernate it would be doing something similar that I do in my stored procedure with temp tables...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 31, 2007 5:26 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
It's not. NHibernate just uses the underlying database's limit and top keyword-equivalents as far as I know.

Cheers,

Symon.


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.