-->
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.  [ 2 posts ] 
Author Message
 Post subject: Group by alias or by subselect
PostPosted: Tue May 27, 2008 4:31 pm 
Newbie

Joined: Tue May 02, 2006 3:17 pm
Posts: 3
Hello all, I have a special case where I would like to group by a subselect. Here is the code



Code:
public List findAverageScoreByMember(int maxResults) {
      log.debug("finding Contentrating instance by member");
      try {
         String queryString = "select (select d.member from Document d where d.documentId = model.contentId), sum(model.score), count(model), ( sum(model.score) / count(model) ) from Contentrating as model group by (select d.member from Document d where d.documentId = model.contentId) order by ( sum(model.score) / count(model) ) DESC";
         
         HibernateTemplate hibernateTemplate = getHibernateTemplate();
         hibernateTemplate.setMaxResults(maxResults);
         List results = hibernateTemplate.find(queryString);
         return results;
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
   }


I need to group by a subselect, the reason is because my tables to not have a link between them therefore no join possible. I subselect to get the member ID and would need to group by this ID. I have tried with an alisas, even tried with the whole subselect statement in the group by without any luck. Anyone have any ideas?

PS : I am using hibernate template with Spring, therefore no need for the callback code and stuff


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 3:45 pm 
Newbie

Joined: Tue May 02, 2006 3:17 pm
Posts: 3
bump


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