-->
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.  [ 1 post ] 
Author Message
 Post subject: problem with group by clause in hql query
PostPosted: Wed Jul 27, 2005 4:38 pm 
Newbie

Joined: Thu Jun 16, 2005 5:53 pm
Posts: 9
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();
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.