I want to be able to add arbitrary number of calculated columns (determined
at runtime) to a query and have those results placed into a Map along with
predefined columns. For example,
<resultMap id="someOrder">
<result property="id" column="ID"/>
<result property="order" column="ORDER"/>
<result property="total" column="ORDER_TOTAL"/>
<result property="calculations" resultMap="GenericMap"/>
</resultMap>
<resultMap id="GenericMap" class="Map"/>
<select id="getOrderStats" resultMap="someOrder">
select id, order, order_total, $calcColumns$
from main_orders
where .... etc etc ...
</select>
Using this example, one might pass $calcColumn$ = "total*0.08 as \"
calculations.tax\", total/quantity as \"calculations.avgcost\""
This should map all columns with the name "calculations.XXX" into a Map
using put(XXX, * ). Currently the code only allows using setXXX( * ). But
since Map obviously doesn't have any setter methods, this fails to populate
the calculations property.
One ugly workaround requires running 2 queries (one with just predefined
columns and the other with the calculated columns) and having Java match the
two result sets. Is there any other way without running 2 queries? I
tried to send this issue as an iBatis improvement but got rejected. Thanks.