I have found a group by alias bug in CreateQuery:
Code:
IQuery q = sess.CreateQuery("select g.StudyCategory.StudyCategoryID, g.StudyCategory.Name, count(*) from Grantee g inner join g.Grants gd where gd.Grant.GrantID = :grantID group by g.StudyCategory.StudyCategoryID, g.StudyCategory.Name");
Throws:
ERROR: 42803: column "studycateg3_.studycategoryid" must appear in the GROUP BY clause or be used in an aggregate function
Generated SQL:
Code:
select studycateg3_.studycategoryid as x0_0_,
studycateg3_.name as x1_0_
from grantees grantee0_ inner join grantee_grants grants1_ on grantee0_.granteeid=grants1_.granteeid inner join grantee_grants grantdetai2_ on grants1_.granteegrantid=grantdetai2_.granteegrantid, study_categories studycateg3_
where grantee0_.studycategoryid=studycateg3_.studycategoryid and ((grantdetai2_.grantid=? ))
group by grantee0_.studycategoryid , studycateg3_.name
In the the group by, the first field's alias should by "studycateg3_" or "grantee0_" in the select.
I managed to make it work by adding an otherwise unnecessary join:
Code:
IQuery q = sess.CreateQuery("select sc.StudyCategoryID, sc.Name, count(*) from Grantee g inner join g.Grants gd inner join g.StudyCategory sc where gd.Grant.GrantID = :grantID group by sc.StudyCategoryID, sc.Name");
Should I submit a bug report?
Cheers.
Alex