ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Butler" <jeffgbut...@gmail.com>
Subject Re: 1 to N in queryForObject()
Date Mon, 31 Jul 2006 14:22:09 GMT
iBATIS has good support for this.  You'll need to use a List instead of an
array, and the "groupBy" keyword on your result map.  Look in the
developer's guide for more information.

Jeff Butler


On 7/31/06, Jane Phillips <jane22124@yahoo.com> wrote:
>
>  Hi, I am new to iBatis. I have a question for one of my query. I have
> tables:
>
> 1.  Product
>     -- product_id
>     -- product_description
>     -- product_name
>
> 2. Items
>     -- item_id
>     -- product_id
>     -- item_description
>     -- item_name
>
> The relationship is one product can have many items. query I would like to
> do is :
> <sqlMap>
> <select id="getProductItems" resultClass="com.abc.products">
>
> SELECT product_id, product_description,product_name, item_name from
> product a, items b WHERE a.product_id = b.product_id and a.product_id =
> #id#
> </select>
> </sqlMap>
>
> in java, com.abc.products:
>
> String product_name;
> String product_description;
> String product_id;
> String[] item_name;
> and all the getXXX and setXXX methods.
>
> The goal is run this query using queryForObject() to get one product and
> all its items to a products object instead of queryForList() to get
> collection of product object with duplicate product_name,
> product_description and product_id. Is it feasible? And how to config the
> sqlMap or other things to do it ?
>
> Please advise
>
>
>
> ------------------------------
> See the all-new, redesigned Yahoo.com <http://yahoo.com/>. Check it out.<http://us.rd.yahoo.com/evt=40762/*http://www.yahoo.com/preview>
>
>

Mime
View raw message