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.  [ 2 posts ] 
Author Message
 Post subject: Count of rows when executing big SQL query with SetFirstResu
PostPosted: Fri Sep 15, 2006 3:58 am 
Newbie

Joined: Wed Sep 13, 2006 5:24 am
Posts: 3
I use named SQL query with very complicated syntax and quite long-timed to execute (using inner selects and MS SQL specific contains keyword).

Then IQuery query = context.Session.GetNamedQuery("QueryName"); is used.
For selecting only required results following code is used.

query.SetFirstResult(5);
query.SetMaxResults(15);

As I understand, sql query is executed, result set contains all records (all rows) and only 5-15 of them are mapped to objects by NHibernate. Obviously, NHibernate does not add anything to SQL query (for example SELECT TOP x).
Is it right? Does NHibernate uses some specific technic to perform setFirstResult and SetMaxResults?

Then - is it possible to get the amount of total rows returned (not mapped)? I do not want to execute the same query with select count(*) again in addition to previous call. Is it possible? Probably, what is needed is to get affected rows count only.

Thanks!


Top
 Profile  
 
 Post subject: Re: Count of rows when executing big SQL query with SetFirst
PostPosted: Fri Sep 15, 2006 4:45 am 
Newbie

Joined: Thu Apr 27, 2006 6:03 am
Posts: 14
PavelB wrote:
As I understand, sql query is executed, result set contains all records (all rows) and only 5-15 of them are mapped to objects by NHibernate. Obviously, NHibernate does not add anything to SQL query (for example SELECT TOP x).
Is it right?


No, NHibernate does use the TOP clause. You can view the generated SQL using NHibernate logging (hibernate.show_sql=true) or SQL Server Profiler.


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