ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: [IBatis3-beta10] nested results for collection
Date Wed, 07 Apr 2010 18:51:10 GMT
Weird that an error was not thrown in that case... I'll have a look to see
why this condition would go ignored.

Thanks for tracking the defect down.  If you get a chance, copy this message
into a Jira defect.

Clinton

On Wed, Apr 7, 2010 at 12:41 PM, Viv Kapadekar <vivek@peoplepowerco.com>wrote:

> Ah, found it. The column attribute was missing from Collection. Added that
> and it worked.
>
>
> <collection property="carParts" *column="id"* javaType="ArrayList"
> ofType="Parts" select="getCarPartInfo"/>
>
>
> 2010-04-07 11:38:47,254 DEBUG [iBatisImplTest] Car id 1 name Audi
> 2010-04-07 11:38:47,255 DEBUG [iBatisImplTest]  car Part iterator is not
> null 3
> 2010-04-07 11:38:47,255 DEBUG [iBatisImplTest] Car Part  index 100  Name
> door
> 2010-04-07 11:38:47,255 DEBUG [iBatisImplTest] Car Part  index 101  Name
> windshield
> 2010-04-07 11:38:47,256 DEBUG [iBatisImplTest] Car Part  index 102  Name
> Brakes
>
>
>
> Hi Clinton
>
> Basically what I am seeing is the nested select is not getting executed. To
> make it simpler, I created a simple prototype.  I know in this example I
> don't need to create a separate select, but wondering why its not working.
> Here are the details
>
> *POJOs*
> public class Car
> {
> private int carId ;
>  private String name ;
>
> private List<Parts> carParts ;
> }
>
>
> public class Parts
> {
> private int partId;
>  private String name ;
> }
>
> *==============*
> *Mapper*
>
> <resultMap id="carResult" type="Car">
>  <id property="carId" column="id"/>
>  <result  property="name" column="name"/>
>  <collection property="carParts" javaType="ArrayList" ofType="Parts"
> select="getCarPartInfo"/>
>  </resultMap>
>
> <select id="getCarsInfo" resultMap="carResult">
>  SELECT car_id as "id", name
> FROM Car where car_id=1
>  </select>
>
> <select id="getCarPartInfo" resultType="Parts">
>  SELECT part_id as "partId", name
> FROM Parts where car_id=1
>  </select>
> ==========
> Tables
> ======
>
>
> mysql> select * from car;
> +--------+------+
> | car_id | name |
> +--------+------+
> |      1 | Audi |
> +--------+------+
> 1 row in set (0.00 sec)
>
>
> mysql> select * from Parts;
> +---------+------------+--------+
> | part_id | name       | car_id |
> +---------+------------+--------+
> |     100 | door       |      1 |
> |     101 | windshield |      1 |
> |     102 | Brakes     |      1 |
> +---------+------------+--------+
> 3 rows in set (0.00 sec)
>
>
> =========================
>
> *Unit Test*
> *
> *
> **
> *
> public void testGetCarInfo() {
>  List<Car> list = repository.getCarsInfo();
> for (Iterator<Car> carIter = list.iterator();carIter.hasNext();) {
>  Car d = carIter.next();
> logger.debug("Car id " + d.getCarId() + " name " + d.getName());
>  List<Parts> dPartList = d.getCarParts();
> if (dPartList!=null) {
>  logger.debug(" car Part iterator is not null " + dPartList.size());
>  } else {
> logger.debug(" car Part List is  null " );
>  }
>
> }
>  assertNotNull("At least one device must exist", list);
>  }
> *
>
>
>
> Unit Test Result
>
> 2010-04-07 11:27:11,576 DEBUG [iBatisImplTest] Car id 1 name Audi
> 2010-04-07 11:27:11,577 DEBUG [iBatisImplTest]  car Part List is  null
>
>
> As you can see the result does not contain the Parts List, the Collection
> is not getting set. What is missing?
>
> -V
>
>
>
>
>
> On Apr 6, 2010, at 8:49 PM, Clinton Begin wrote:
>
> So you have desc in two places?  This is getting more confusing.  Maybe
> post the expected result set and the classes you're mapping it to.
>
> Clinton
>
> On Tue, Apr 6, 2010 at 9:09 PM, Viv Kapadekar <vivek@peoplepowerco.com>wrote:
>
>> Yeah actually to make it more clear Class X also has desc. So its really:
>> Class X {
>> String id
>> String desc
>> List<Y> b
>> }
>> If index is null the desc is applicable for X and when its not null it
>> should be applicable to X.
>>
>> --V
>>
>> On Apr 6, 2010, at 7:21 PM, Clinton Begin wrote:
>>
>> If iBATIS finds ANY values for the mapped properties, it will create the
>> object.  Is it possible that the desc column is populated even when the
>> index is null?
>>
>> On Tue, Apr 6, 2010 at 7:52 PM, Viv Kapadekar <vivek@peoplepowerco.com>wrote:
>>
>>> Hi
>>> I have a Class X containing a List of Class Y
>>>
>>> Class X {
>>> String a
>>> List<Y> b
>>> }
>>>
>>> Class Y {
>>> String index
>>> String desc
>>> }
>>>
>>> The resultMap I have is
>>>
>>> <resultMap id="someID" type="X">
>>>                <id property="a" column="id"/>
>>>                        <collection property="b" ofType="Y">
>>>                                      <id property="index" column="index"
>>> />
>>>                                        <result property="desc"
>>> column="desc"/>  -->
>>>                        </collection>
>>> </resultMap>
>>>
>>> This is fine, but I don't want the resulting X to have the collection b
>>> set, if the "index" value is null. If index is null, even the value of b in
>>> X should be null.  I tried using <discriminator> and also tried creating
a
>>> separate sql, but no luck. Any ideas?
>>>
>>> -V
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>
>>>
>>
>>  ---------------------------------------------------------------
>> Viv Kapadekar
>> vivek@peoplepowerco.com
>>
>>
>
> ---------------------------------------------------------------
> Viv Kapadekar
> vivek@peoplepowerco.com
>
>
>  ---------------------------------------------------------------
> Viv Kapadekar
> vivek@peoplepowerco.com
>
>

Mime
View raw message