-->
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.  [ 3 posts ] 
Author Message
 Post subject: Incorrect Order By clause generated
PostPosted: Fri Nov 18, 2005 8:34 pm 
Regular
Regular

Joined: Sun Sep 25, 2005 11:35 pm
Posts: 57
Here is my HQL:
Code:
select episode.EpisodeKey, max(schedule.StartTime)
    from EpisodeImpl episode
         join episode.Schedules schedule
    group by episode.EpisodeKey
    order by schedule.StartTime desc


When this executes I get the following error from SQL Server 2000:

Code:
NHibernate.ADOException: Could not execute query ---> System.Data.SqlClient.SqlException:
Column name 'schedules1_.START_TIME' is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.


Here's the SQL that was generated by NHibernate:
Code:
select
    episodeimp0_.EPISODE_KEY as x0_0_,
    max(schedules1_.START_TIME) as x1_0_
from Episode episodeimp0_
    inner join Schedule schedules1_
    on episodeimp0_.EPISODE_KEY=schedules1_.EPISODE_FK
group by  episodeimp0_.EPISODE_KEY
order by  schedules1_.START_TIME desc


If I modify the order by clause to "order by x1_0_ desc" and submit the SQL manually, it works without any problems. What can I do to make my HQL work?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 10:21 am 
Regular
Regular

Joined: Sun Sep 25, 2005 11:35 pm
Posts: 57
Can anyone think of a workaround for this poblem? I have tried to change the HQL a bit, but couldn't get it to generate SQL that SQL Server would accept.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 5:39 pm 
Regular
Regular

Joined: Sun Sep 25, 2005 11:35 pm
Posts: 57
Never mind, my collegue figured this out. We changed the order by clause to "order by max(schedule.StartTime) desc" and now it works!


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