-->
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: Simple group by, without getting back projection object
PostPosted: Wed Apr 26, 2006 8:56 am 
Newbie

Joined: Wed Apr 20, 2005 5:05 pm
Posts: 12
Hello,

I think I have a simple problem, but the solution eludes me. First off, I know I can just use HQL to do this. I'll go this route if i need to, but ive built a wrapper around the criteria framework so i can manipulate my result data from outside the hibernate layer.

My Problem: I have a table that rows of data, with a date column...simplified query is below.
Code:
select DATE_FORMAT(a_date, '%Y-%m-%d'), count(*), sum(price) from total group by  to_days(a_date);
Using formulas, I have gotten 90% there. basically the group by consolidates the date column by days. The count pulls the number of rows and the sum adds up all of the consolidated prices for that day. So I need to group by the date column to give me the information back as I need it.

If i use
Code:
criteria.setProjection(Projections.groupProperty("aDate"));
i get back the date...when I really just want to group the rows together to get me back the ROOT_ENTITY object.

criteria.setResultTransformer(Criteria.ROOT_ENTITY)...doesn't work.

Any ideas?

Thx.
LT


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 1:11 pm 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
Are you looking for:
session.createCriteria( Entity1.class ).setProjection(Projections.projectionList().add(Projections.groupProperty("col1")).add(Projections.rowCount()).add(Projections.sum("col2"))).list(); ??

This would return a list of object[] (three elements). You could then set an appropriate ResultTransformer -- ROOT_ENTITY is probably not going to do it as, I assume, your ROOT_ENTITY has additional properties. Take a look at AliasToBeanResultTransformer.

Good luck
Curtis ...

_________________
---- Don't forget to rate! ----


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.