-->
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: Paging Issues
PostPosted: Wed Dec 14, 2005 7:15 pm 
Newbie

Joined: Sun Oct 23, 2005 3:42 am
Posts: 7
Location: Minsk, Belarus
Hello,

Please help me with the following issue

I want to set paging for my queries. So proceed in the following way:
Code:
            IQuery query = m_Session.CreateQuery("select pr from Project as pr order by pr.Name asc");
            query.SetMaxResults(pageSize);
            query.SetFirstResult(pageIndex * pageSize);
            return query.List();


The query
Code:
select pr from Project as pr order by pr.Name asc
executed as

Code:
            IQuery query = m_Session.CreateQuery("select pr from Project as pr order by pr.Name asc");
            return query.List();
[/code]

works fine. But when I try to set paging I get the following:

Quote:
Tp.UnitTests.SelectQueryTest.Paging : NHibernate.ADOException : Could not execute query
----> System.Data.SqlClient.SqlException : Column name 'project0_.Name' is invalid in the ORDER BY clause because it is not contained in an aggregate function and there is no GROUP BY clause.


I checked using SQL profiler and found that NHibernate forms the following query before forming the page select:

"select Count(*) as x0_0_ from Project project0_ order by [project0_].[Name] asc".

As you see - it is incorrect. Is it a bug or limitation to use NH paging only without order by? As I understand NH doesn't truncate the order by when it posts count select to know the total count of rows for forming the main page select query.

Please let me know if I am wrong or if you can help me.

Thanks.


Top
 Profile  
 
 Post subject: The solution was found
PostPosted: Thu Dec 15, 2005 6:35 pm 
Newbie

Joined: Sun Oct 23, 2005 3:42 am
Posts: 7
Location: Minsk, Belarus
The topic is closed.


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.