You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Nicholas Piasecki <ni...@piasecki.name> on 2007/08/21 00:13:56 UTC

Lists of primitives in result maps doesn't work?

I might be having a moment, but here goes.

I have a Coupon class that contains an integer list of BrandIds that 
specifies which brands of product the coupon is good for. We don't want 
the whole Brand object because it contains a lot of information that's 
not necessary for the coupon's CalculateDiscount() method to function, 
so we'd just like a list of integers returned from iBATIS. int[], 
List<int>, just a list of integers of some sort.

The relevant parts of the database tables look like this:

Coupons:
   CouponId (PK)
   Code

Coupons_Brands: (M:N relationship table)
   CouponId (FK)
   BrandId (FK)

To avoid the N+1 selects, we tried a SQL statement like the following:

SELECT
cou.CouponId AS CouponId,
cou.Code AS CouponCode,
cou_b.BrandId AS CouponBrandId,
FROM SkiviezInv.Coupons AS cou
LEFT OUTER JOIN Coupons_Brands AS cou_b
ON cou.CouponId = cou_b.CouponId

But then we got stuck at defining the <resultMap>. Just using the 
property and column attributes doesn't work ("no type handler for List`1 
is registered"). The furthest we got was defining another result map for 
the integer type, like this:

<resultMap id="ResultMapCoupon" class="Coupon" groupBy="Id">
    <result column="CouponId" property="Id" />
    <result
      property="BrandIds"
      resultMapping="Coupon.ResultMapCouponBrandId" />
</resultMap>

<resultMap id="ResultMapCouponBrandId" class="int">
    <result property="value" column="CouponBrandId" />
</resultMap>

This set up would indeed create a List<int> with the proper Count (e.g., 
two BrandIds), but they're always all set to 0. It seems like this would 
be supported (see example 3.41 in the DataMapper documentation), but it 
just doesn't seem to work.

We've worked around it by just using the select attribute and getting 
rid of the join.

This is on DataMapper 1.6.1.

Thanks for any insight!

V/R,
Nicholas Piasecki

Re: Lists of primitives in result maps doesn't work?

Posted by Miika Mäkinen <mm...@gmail.com>.
I had similar problems... could not get a list of strings working. In the
end I made a class with one property.
I think it's a bug.

On 8/21/07, Nicholas Piasecki <ni...@piasecki.name> wrote:
>
> I might be having a moment, but here goes.
>
> I have a Coupon class that contains an integer list of BrandIds that
> specifies which brands of product the coupon is good for. We don't want
> the whole Brand object because it contains a lot of information that's
> not necessary for the coupon's CalculateDiscount() method to function,
> so we'd just like a list of integers returned from iBATIS. int[],
> List<int>, just a list of integers of some sort.
>
> The relevant parts of the database tables look like this:
>
> Coupons:
>    CouponId (PK)
>    Code
>
> Coupons_Brands: (M:N relationship table)
>    CouponId (FK)
>    BrandId (FK)
>
> To avoid the N+1 selects, we tried a SQL statement like the following:
>
> SELECT
> cou.CouponId AS CouponId,
> cou.Code AS CouponCode,
> cou_b.BrandId AS CouponBrandId,
> FROM SkiviezInv.Coupons AS cou
> LEFT OUTER JOIN Coupons_Brands AS cou_b
> ON cou.CouponId = cou_b.CouponId
>
> But then we got stuck at defining the <resultMap>. Just using the
> property and column attributes doesn't work ("no type handler for List`1
> is registered"). The furthest we got was defining another result map for
> the integer type, like this:
>
> <resultMap id="ResultMapCoupon" class="Coupon" groupBy="Id">
>     <result column="CouponId" property="Id" />
>     <result
>       property="BrandIds"
>       resultMapping="Coupon.ResultMapCouponBrandId" />
> </resultMap>
>
> <resultMap id="ResultMapCouponBrandId" class="int">
>     <result property="value" column="CouponBrandId" />
> </resultMap>
>
> This set up would indeed create a List<int> with the proper Count (e.g.,
> two BrandIds), but they're always all set to 0. It seems like this would
> be supported (see example 3.41 in the DataMapper documentation), but it
> just doesn't seem to work.
>
> We've worked around it by just using the select attribute and getting
> rid of the join.
>
> This is on DataMapper 1.6.1.
>
> Thanks for any insight!
>
> V/R,
> Nicholas Piasecki
>

Re: Lists of primitives in result maps doesn't work?

Posted by Gilles Bayon <ib...@gmail.com>.
Correction in SVN

-- 
Cheers,
Gilles

<a href="http://www.amazon.com/gp/registry/6JCP7AORB0LE">Wish List</a>