Hello there,
we have a problem when we try to get the sum of a composite field of a mapped class. The composite field is a MonetaryAmount, containing an amount (Double) and a currency (String).
Since composite fields can not be 'summed', we have to use the DBMS functions such as DECiMAL or VARCHAR in order to concatenate the currency to the sum of amounts.
Apparently, Hibernate does not recognize those key words and throws exceptions (e.g. "undefined alias" or "( expected before )").
Although the equivalent SQL query works fine when accessing DB2 directly (using TOAD for DB2 or Squirel), we can't get through using HQL.
Does anybody know a workaround for our problem?
Thank you in advance.
Code:
select varchar(char(decimal(obj.value.amount,5,2),',')) || obj.value.currency
from MyObject as obj
Hibernate version: 2.1.7
Full stack trace of any exception that occurs:
1 errors occurred while listing (and calling getPathNames).
net.sf.hibernate.QueryException: ( expected before ) in select [select varchar(char(decimal(obj.value.amount,5,2),',')) || obj.value.currency
from MyObject as obj]
Name and version of the database you are using: IBM DB2 v8.2
The generated SQL (show_sql=true): none