ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Danny Lin <da...@trionworld.com>
Subject n+1 selects and queryForMap
Date Thu, 03 Apr 2008 17:30:39 GMT

I have an object with a property that is a HashMap of name/value pairs from a separate data
table. If one of my properties on the 'food' class is a hashmap, I'm assuming I can create
that hashmap using the following sql mapping correct?

Is it possible to avoid the n+1 select issue and solve this problem using another method?
Would this be a case to use a row handler?


food_id            int
food_name      varchar(256)

food_id            int
name               varchar(64)
value               varchar(64)

<resultMap id="food" class="food" >
            <result property="foodId" column="food_id"/>
            <result property="foodName" column="food_name"/>
<result property="foodAttributes" select="getFoodAttributes"/>

<resultMap id="foodAttributes " class="java.util.HashMap" >
               <result property="name" column="name"/>
               <result property="value" column="value"/>

<select id="getFood" resultMap="food" parameterClass="int">
            select * from food where food_id=#id#

<select id="getFoodAttributes" resultMap="foodAttributes" parameterClass="int">
            select * from food_attributes where food_id=#id#


View raw message