-->
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.  [ 3 posts ] 
Author Message
 Post subject: using createCriteria with aggregate function "sum"
PostPosted: Sun Feb 13, 2005 4:57 pm 
Newbie

Joined: Sun Feb 13, 2005 4:48 pm
Posts: 1
Hi there,

I am a newbie. But I managed to create a small application using hibernate and mysql database.

There is one thing which I am trying to achieve but not sure how.

There is a report which is generated from a view. I provide search parameters using a struts form bean and get the results in a arraylist. Works like a charm so far. I have pasted the code below...

BillingReportForm billingreport = (BillingReportForm) form; // get the form bean

System.out.println( "entering BillingReportForm action..." );
String fwd = "success" ;
HttpSession session = request.getSession();

Session sessionDB = HibernateUtil.currentSession();
Transaction tx = sessionDB.beginTransaction();

String searchValue = request.getParameter("searchValue");

if( ("search").equalsIgnoreCase(searchValue) )
{
System.out.println( "entering search results billing report action..." ) ;
Example example = Example.create(billingreport)
.excludeZeroes() //exclude zero valued properties
.ignoreCase() //perform case insensitive string comparisons
.enableLike(); //use like for string comparisons

List result = sessionDB.createCriteria(BillingReportForm.class)
.add(example)
.list();
billingreport.setBillingreports(result);

System.out.println( "Billingreports Size ---->" + billingreport.getBillingreports().size() );
}


Say for example it gives me 10 rows. There is a one column which gives me the "amount due" for each row. I am trying to get the total of that column and provide it in the bottom of the table.

There are couple ways to do this. I can assign a variable in jsp and keep adding the amount to the variable and then show it.

I thought it would be better to use hibernate to do that for me. The option I have right now is, create another query below the existing one, using the same criteria give me only the total amount due using aggregate function. Is there any other way to achieve this? Since I am new I am not sure if I am missing something here.

Regards,
Raaj


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 9:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have not looked at the details as yet but Hibernate 3.x has/will-have support for this. I suggest you check the current state of the betas to determine where they are up to.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 5:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I blogged some examples for the new Criteria enhancements too, here: http://javablogs.com/Jump.action?id=198498


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