Hi,
I read on the docs at hibernate.org you can do a group by like this:
Code:
public IList FindTopPosters(int resultLimit)
{
StringBuilder hql = new StringBuilder();
hql.Append("select user from User user ");
hql.Append("inner join user.JournalsOwned journal ");
hql.Append("inner join journal.JournalEntries entry ");
hql.Append("group by user ");
hql.Append("order by count(user) asc ");
IQuery q = session.CreateQuery(hql.ToString());
q.SetMaxResults(resultLimit);
return q.List();
}
But it doesn't work, I get an error that says I need to specify all the columns in the group by clause.
So I changed the code to the following and it works fine, but I think the code above should work too right?
Code:
public IList FindTopPosters(int resultLimit)
{
StringBuilder hql = new StringBuilder();
hql.Append("select user from User user ");
hql.Append("inner join user.JournalsOwned journal ");
hql.Append("inner join journal.JournalEntries entry ");
hql.Append("group by user.Id, user.FirstName, user.LastName, user.Email, user.Username, user.Password, user.CreationDate, user.AccountPrivate, user.AccountActive, user.ReceiveCommentsEmail, user.ActivationCode, user.Gender, user.CountryId, user.LastSignedIn ");
hql.Append("order by count(user.FirstName) asc ");
IQuery q = session.CreateQuery(hql.ToString());
q.SetMaxResults(resultLimit);
return q.List();
}