ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jane Phillips <jane22...@yahoo.com>
Subject Re: 1 to N in queryForObject()
Date Tue, 01 Aug 2006 12:29:01 GMT
I looked at the wiki. Not sure I got them all. I still have error: "Attribute "groupBy" must
be declared for element type "resultMap". Please help !
   
  Here are my sqlmap and java.
   
  -- java
  String productId;
String productName;
String productDesc;
ArrayList itemName;
  all getXXX and setXXX
  
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="prod">
   <resultMap id="prodMap" class="com.abc.Products" groupBy="productId">
  <result property="productId" column="productId"/>
  <result property="productName" column="productName"/>
  <result property="productDesc" column="productDesc"/>
  <result property="item" resultMap="prod.itemMap"/>
 </resultMap>
  
 <resultMap id="itemMap" class="java.lang.String">
  <result property="itemName" column="itemName"/>
   </resultMap>
   <select id="getProductItems" resultMap="prodMap">
  select a.product_id as productId,
 a.product_name as productName,
 a.product_desc as productDesc,
 b.item_name as itemName
  from products a , items b
  where a.product_id = b.product_id
   
 </select>
  </sqlMap>

  I am using queryForList() trying to get list of product. within each product I should have
collection of items (item names).
   
  Thanks so much,
   
  
Larry Meadors <lmeadors@apache.org> wrote:
  ...and the WIKI:

http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+get+around+the+N+Plus+1+selects+problem

If you follow the instructions on the WIKI and find any issues, please
feel free to add another example, or make corrections.

Larry


On 7/31/06, Jeff Butler wrote:
>
> 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 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 :
> > 
> > > >> > 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#>
>
> > 
> >
> > 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. Check it out.
> >
> >
> >
> >
> >
> >
>
>


 		
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2ยข/min
or less.
Mime
View raw message