-->
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: How do I map an aggregate value to a persistant object?
PostPosted: Fri Apr 06, 2007 8:38 pm 
Newbie

Joined: Fri Apr 06, 2007 8:31 pm
Posts: 7
I need to have objects which have sum and avg of certain columns along with other column values as properties . The sql uses group by.

Is there a way to have these aggregate values as part of the class? I really appreciate any help.

In the docs, I read that this is possible in report queries which is outputted immediately before session close. But this is not assigned to the persistent class

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 07, 2007 6:47 am 
Newbie

Joined: Sun Oct 08, 2006 8:03 am
Posts: 14
I'm not sure I understand what you want. As I see it, your object should have either the calculated aggregate, or a persistent value.

For example, pretend you have a table of assets, where each asset has a value. You may want to know what the total value of assets is. You can either store a persistent number in the database, or you can calculate the total at any time you need it.

If you try to store the total, rather than calculate it when you need it, what happens when one of the assets values is updated, or when an asset is inserted or deleted? Won't the stored value then be out-of-date?

Is it really necessary to have the aggregates and the other column values in the same object? Maybe you can provide more details of your application.

John.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 07, 2007 7:38 am 
Newbie

Joined: Sat Apr 07, 2007 6:53 am
Posts: 16
If I unsdrestant what do you see, you have to map this properties using formula attribute. For example:

Code:
<property name="totalincluding TAX" formula="TOTAL + TAX_RATE * TOTAL"/>


or,

Code:
<property name="..." formula=" SELECT AVG(b.Amount) FROM BID b..."/>


I hope help you.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 08, 2007 8:17 pm 
Newbie

Joined: Fri Apr 06, 2007 8:31 pm
Posts: 7
Thanks for your reply..Let me explain my situation more...

I have a table with columns - siteid, channelid, sent, errors.

I want to create a table with siteid, channelid, total sent, total errors group by siteid and channelid.

Basically my mapped class should hold values of siteid, channelid, total sent for each site+channel combination and total errors for each site+channel combination .

I dont know how to have the total values map to the class..

I have seen examples of how to execute a native query and loop through rows to display values including aggregate values..But these are not mapped to any class...Also we need to keep the session open until we loop through the rows.

I really appreciate any help in this regard...

Thanks
attups


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.