-->
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.  [ 4 posts ] 
Author Message
 Post subject: Result from Projections on Criteria queries
PostPosted: Tue Nov 22, 2005 5:23 pm 
Beginner
Beginner

Joined: Tue Nov 22, 2005 4:53 pm
Posts: 41
Location: Netherlands
Can someone explain me why with Projections added to a Criteria query, you get a Object[] as a result in de List result ?

I was using the Projections this afternoon and the documentation on how to implement them are very complete, but they do not mention the processing of the result.

After some debugging I found out that it returned a Object[] in the List.

I'd suspected just a regular List to iterate, or even better: a Map .. ie:

Code:
List results = session.createCriteria(Cat.class)
    .setProjection( Projections.projectionList()
        .add( Projections.avg("weight").as(avgWeight" )
        .add( Projections.max("weight").as(maxWeight" )
    )
    .list();
Map projection = (Map)results.get(0);
BigDecimal avgWeight = (BigDecimal)projection.get("avgWeight");
// etc..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 4:11 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 4:53 pm
Posts: 41
Location: Netherlands
*kick*

Does anyone have any opinion about this? :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 5:00 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
your query is Scalar Query (with Average, Max, SUM Aggregate function), return array (Object[] ). For more info look into the below link
http://www.hibernate.org/hib_docs/refer ... larqueries

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 11:05 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 4:53 pm
Posts: 41
Location: Netherlands
true, but that only describes the HQL and not the Criteria.

I'm just curious why there isn't some sort of method us can use on aggregated Criteria query's to get a map with the result.


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