-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL or Criteria? finding average and most distinct record
PostPosted: Wed Jul 16, 2008 1:38 pm 
Newbie

Joined: Thu Apr 17, 2008 3:46 pm
Posts: 5
I am using a spring / hibernate 3 stack.

I have 2 issues.... but they are somewhat related so I decided to throw them into 1 post:

Background:
I have the following table (or something similar)
GROUP_ID - PK
EFFECTIVE_DATE - PK
UPDATE_DATE -PK
TYPE - PK
AMOUNT

As you can see, it is a table with a composite key. I have all my domain objects mapped out properly with the table so there is no issue there.

1. Either through HQL or Criteria.... how do I get a record(with a known GROUP_ID and TYPE) with the most recent EFFECTIVE_DATE and most recent UPDATE_DATE.


2. Given an EFFECTIVE_DATE range (ie july 1 to july 10), how can I find the average AMOUNT per day... with the following things to keep in mind:
a: There will not be a record for every day. For example, July 5 does not have a record, so it has to use the last known amount which may have been July 3.
b: There are multiple instances of the same effective day, but for the average calculation I must use the latest amount for that day which can be determined by the latest UPDATE_DATE

It may be the case where I have to grab a set of data and manually filter out the data for my calculation or there may be some hibernate magic I can do. In either case, any suggestions or strategies would be most welcome.

Thanks in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.