association + collection nested populates only with one row

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

association + collection nested populates only with one row

Jose María Zaragoza
Hi :


I'm using MyBatis 3.4.4
I have got a database model where one Employee has-one Person entity,
and a Person has-many Car entities
For example, if I query for Employee entity with ID_EMPLOYEE  = 1, I get

ID_EMPLOYEE | NUMBER_EMPLOYEE | ID_PERSONAL | ID_CAR |  NAME_CAR
-----------------------------------------------------------------------------------------------------------------------
1                                   1
       1                    1                Ford

1                                   1
       1                    2                Nissan


But with the next resultMap ( association + collection nested ) ,
the list of cars ( List<Car> cars ) is populated only with one car (
the row [2 , Nissan] )

is it possible this combination ( association + collection nested ) ?




<resultMap type="Employee" id="EmployeeResultMap">
        <id property="idEmployee" column="ID_EMPLOYEE"/>
        <result property = "numberEmployee" column="NUMBER_EMPLOYEE"/>
         <association property="person" javaType="Person">
                  <id property="idPersonal" column="ID_PERSONAL" />
                 <collection property="cars" ofType="Car">
                     <id property="idCar" column="ID_CAR" />
                     <result property="nameCar" column="NAME_CAR" />
                 </collection>
          </association>
</resultMap>

/* Class model */

class Employee{

Integer idEmployee;
Integer numberEmployee;
Person person;

}


class Person{

Integer idPersonal;
List<Car> cars;

}

class Car{

Integer idCar;
String  nameCar;

}

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: association + collection nested populates only with one row

Iwao AVE!
Hi Jose,

It should work as you expect.
Can you create a test case or example project that reproduces the issue? Then I'll look into it.

Regards,
Iwao

2018-03-23 16:51 GMT+09:00 Jose María Zaragoza <[hidden email]>:
Hi :


I'm using MyBatis 3.4.4
I have got a database model where one Employee has-one Person entity,
and a Person has-many Car entities
For example, if I query for Employee entity with ID_EMPLOYEE  = 1, I get

ID_EMPLOYEE | NUMBER_EMPLOYEE | ID_PERSONAL | ID_CAR |  NAME_CAR
-----------------------------------------------------------------------------------------------------------------------
1                                   1
       1                    1                Ford

1                                   1
       1                    2                Nissan


But with the next resultMap ( association + collection nested ) ,
the list of cars ( List<Car> cars ) is populated only with one car (
the row [2 , Nissan] )

is it possible this combination ( association + collection nested ) ?




<resultMap type="Employee" id="EmployeeResultMap">
        <id property="idEmployee" column="ID_EMPLOYEE"/>
        <result property = "numberEmployee" column="NUMBER_EMPLOYEE"/>
         <association property="person" javaType="Person">
                  <id property="idPersonal" column="ID_PERSONAL" />
                 <collection property="cars" ofType="Car">
                     <id property="idCar" column="ID_CAR" />
                     <result property="nameCar" column="NAME_CAR" />
                 </collection>
          </association>
</resultMap>

/* Class model */

class Employee{

Integer idEmployee;
Integer numberEmployee;
Person person;

}


class Person{

Integer idPersonal;
List<Car> cars;

}

class Car{

Integer idCar;
String  nameCar;

}

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: association + collection nested populates only with one row

Jose María Zaragoza
2018-03-23 18:13 GMT+01:00 Iwao AVE! <[hidden email]>:
> Hi Jose,
>
> It should work as you expect.
> Can you create a test case or example project that reproduces the issue?
> Then I'll look into it.
> https://github.com/mybatis/mybatis-3/wiki/Unit-Test
> https://github.com/harawata/mybatis-issues


Thanks,
You are right
It was my fault . A typo writing name of <id> column in resultMap. Not
in this example, but in my real project

Sorry for inconvence



>
> Regards,
> Iwao
>
> 2018-03-23 16:51 GMT+09:00 Jose María Zaragoza <[hidden email]>:
>>
>> Hi :
>>
>>
>> I'm using MyBatis 3.4.4
>> I have got a database model where one Employee has-one Person entity,
>> and a Person has-many Car entities
>> For example, if I query for Employee entity with ID_EMPLOYEE  = 1, I get
>>
>> ID_EMPLOYEE | NUMBER_EMPLOYEE | ID_PERSONAL | ID_CAR |  NAME_CAR
>>
>> -----------------------------------------------------------------------------------------------------------------------
>> 1                                   1
>>        1                    1                Ford
>>
>> 1                                   1
>>        1                    2                Nissan
>>
>>
>> But with the next resultMap ( association + collection nested ) ,
>> the list of cars ( List<Car> cars ) is populated only with one car (
>> the row [2 , Nissan] )
>>
>> is it possible this combination ( association + collection nested ) ?
>>
>>
>>
>>
>> <resultMap type="Employee" id="EmployeeResultMap">
>>         <id property="idEmployee" column="ID_EMPLOYEE"/>
>>         <result property = "numberEmployee" column="NUMBER_EMPLOYEE"/>
>>          <association property="person" javaType="Person">
>>                   <id property="idPersonal" column="ID_PERSONAL" />
>>                  <collection property="cars" ofType="Car">
>>                      <id property="idCar" column="ID_CAR" />
>>                      <result property="nameCar" column="NAME_CAR" />
>>                  </collection>
>>           </association>
>> </resultMap>
>>
>> /* Class model */
>>
>> class Employee{
>>
>> Integer idEmployee;
>> Integer numberEmployee;
>> Person person;
>>
>> }
>>
>>
>> class Person{
>>
>> Integer idPersonal;
>> List<Car> cars;
>>
>> }
>>
>> class Car{
>>
>> Integer idCar;
>> String  nameCar;
>>
>> }
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "mybatis-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [hidden email].
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.