Thanks for the reply.
The original query:
select sum(finacial.ytdNewwrittenpremPl), sum(finacial.ytdRenewalpremPl), ... from Financial as finacial where ..."
This query will give me a list of one object. That object is an array, let's say result. So now I have to call:
Financial sum = new Financial();
int i = 0;
sum.setYtdNewwrittenpremPl((Integer)Array.get(result, i++));
sum.setYtdRenewalpremPl((Integer)Array.get(result, i++));
...
With 20 or more columns, that's a maintainence problem.
Now what I want to do is, instead of getting back
sum(finacial.ytdNewwrittenpremPl), I also want to get an additional row, which is the literal String "ytdNewwrittenpremPl". Therefore, I can use any reflection based technique to do something like this:
for (int i = 0; i < result.size; i++)
{
// get the fieldName, which would be ytdNewwrittenpremPl during first iteration
// get field value, which would be sum(finacial.ytdNewwrittenpremPl) during first iteration.
BeanUtil.copyProperty(sum, fieldName, fieldValue);
}
This is possible in SQL:
select 'ytdNewwrittenpremPl', sum(finacial.ytdNewwrittenpremPl), 'ytdRenewalpremPl', sum(finacial.ytdRenewalpremPl), ... from Financial as finacial where ..."
Basically, you add the String literal to the select.
Clearer?
|