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.  [ 4 posts ] 
Author Message
 Post subject: Paging Functionality
PostPosted: Fri Feb 15, 2008 4:08 am 
Newbie

Joined: Fri Feb 15, 2008 3:50 am
Posts: 2
nHibernate version:
1.2.1

Name and version of the database you are using:
MS SQL 2005


Hi all!!! I have a problem using the paging functionality of nHibernate.
I have a Table called "User" which contains about 100 000 records. My intention is now to always load for example 100 records each (paging functionality).
The Code I use for my C# application looks like this, where @index is the first result I want to receive and @count is the number of results.

Code:
return _util.CurrentSession.CreateCriteria(typeof(User)).SetFirstResult(index).SetMaxResults(count).List<User>();


When I execute to code with the parameters @index=99742 and @count=10, the code which i can see in my sql profiler is:

The generated SQL (show_sql=true):

Code:
SELECT top 99752 this_.recid as recid0_0_, this_.firstname as firstname0_0_, this_.lastname as lastname0_0_, this_.email as email0_0_, this_.address as address0_0_, this_.zip as
zip0_0_, this_.city as city0_0_, this_.telephone as telephone0_0_ FROM users this_



What does this mean: I get 99752 records from my database (at least nhibernate gets all of them, in the code there are really only 10 records). Fetching 99752 records takes a very long time - and that's the problem. It would be much better to optimize the query so that the sql server only returns 10 records. Could anyone please give me some help how i could implement this....

Thanks!!
Best Regard
tredert


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 4:33 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
MS SQL Server 2000 didn't support any mechanism for specifying FIRST and LIMIT like some other RDBMSes so the dialect is designed to request the top start + max_records items and then simply skip over the records up to start before actually hydrating object instances to return. Agreed, this is slow but it's about the best you can expect given the limitations of the query language the database supports.

I know SQL Server 2005 added some query language features to improve this situation, however I don't know whether or not there's an NHibernate dialect that uses them as they're a little arcane. If you're not using the SQL 2005 specific dialect you should try it, but I can't guarantee it will help.

Cheers,

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 4:37 am 
Newbie

Joined: Tue Sep 26, 2006 10:59 am
Posts: 15
I think you use NHibernate.Dialect.MsSql2000Dialect, but you need NHibernate.Dialect.MsSql2005Dialect. Check and fix param "hibernate.dialect" in your config-file.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 5:12 am 
Newbie

Joined: Fri Feb 15, 2008 3:50 am
Posts: 2
thank you sergee. using the 2005dialect gives the expected results...

best regards


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