Stathis Alexopoulos
Stathis Alexopoulos

Reputation: 1009

Aggregate function on composite user type

I have a composite user type that represents a monetary amount. This type spans to two columns.

-Amount
-Currency

When i am creating an HQL query that performs an aggregate function like "avg" on a property using this composite user type an exception is thrown. The reason as it seems is that AvgFunction cannot operate with types that have multiple columns.

Is there any way to use CompositeUserType in aggregate functions?

Thanks in advance and best regards
Stathis Alexopoulos

Upvotes: 2

Views: 569

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

Your query doesn't make much sense. What would be the average of these three rows?

amount    currency
5         USD
10        EUR
15        YEN

You may average the amounts and neglect the currency:

select avg(bill.fullAmount.amount) from BillBean as bill

but you can't average the monetary amounts (i.e. the tuple [amount, currency]).

Upvotes: 2

Related Questions