Yes I've done that but it does not work.  It doesn't bother filling in the
calculations map with anything because iBatis is only looking for getters
and setters and doesn't understand a Map requires special handling.


On 4/19/07, Larry Meadors <[EMAIL PROTECTED]> wrote:

Can you eliminate the result map, and use implicit field mapping instead?

<select id="getOrderStats" resultClass="SomeClass" remapResults="true">
      select
          id,
          order,
          order_total as total,
          $calcColumns$
      from main_orders
      where .... etc etc ...
</select>

Make sure that the constructor for "SomeClass" creates the Map
instance, too - or you'll get an NPE.

Larry


On 4/18/07, Junyi <[EMAIL PROTECTED]> wrote:
> 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.

Reply via email to