-->
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: Getting values from Aggregate Functions (non-POJO)
PostPosted: Thu Apr 29, 2004 11:46 am 
Newbie

Joined: Thu Apr 29, 2004 11:40 am
Posts: 11
Looking for the best way to accomplish the following:

myList = hibernateSession.createQuery(
"select perf.url, avg(perf.time) from com.pg.statistics.performance.PerformanceStatistic as perf where perf.application = :appName group by perf.url"
).setParameter("appName", application).list();

(so returning url [String] and average of time [Aggregate - int] )

I can iterate over "myList" but the returns are Object[].

Current I am doing:
for ( int q = 0; q < myList.size(); q++ ) {
Object[] rets = (Object[])performanceReporting.get(q);
String url = (String)rets[0];
Float avg = (Float)rets[1];
}

But I feel there is a better way (I swear I've seen something before that struck me as better )

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 10:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You can create a DTO POJO which has a constructer matching your data thus your return set will be a List of these objects with the properties set. The query would look like ..

select new my.containerPOJO( perf.url, avg(perf.time)) from .....

See docos for more information.


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.