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?