You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Aleksandr Elbakyan <ra...@yahoo.com> on 2009/04/16 22:35:35 UTC

SubQuery

Hello,


I have 


class A{

private Integer id;

private Set primB;

private Set secBs;

private Set<Integer> allBIds;

......

}

class B{

private Integer id;

private String name;

.....

}


  <select id="getIds" parameterClass="map"  resultClass="java.lang.Integer">

    <![CDATA[

          select distinct B_id from B

          start with

          b_id in (#parentId#,#ids#)

          connect by PRIOR PARENT_B_ID=B_id

        ]]>

  </select>


  <select id="getAs" parameterClass="map"

    resultMap="th.A">

 ....

        ]]>


</select>



  <resultMap id="A" class="my.A">

    <result property="id" column="A_ID" />

    <result property="primB" resultMap="my.PB" />

    <result property="secBs" resultMap="my.SB" />

    <result property="allBIds" select="getIds"/>

  </resultMap>



I don't know how to pass into getIds subquery PrimB and secBs can anybody help please?


Thanks




      

Re: SubQuery

Posted by Nathan Maves <na...@gmail.com>.
Start at the bottom of page 38 of the developers guide.  You might even want
to read the whole thing because it might show you a better way to achieve
what you are looking for.  Right now you have the makings of a n+1 problem.
Nathan

On Thu, Apr 16, 2009 at 2:35 PM, Aleksandr Elbakyan <ra...@yahoo.com>wrote:

> Hello,
>
> I have
>
> class A{
> private Integer id;
> private Set* primB;
> private Set secBs;
> private Set<Integer> allBIds;
> .....
> }
> class B{
> private Integer id;
> private String name;
> ....
> }
>
>   <select id="getIds" parameterClass="map"
>  resultClass="java.lang.Integer">
>     <![CDATA[
>           select distinct B_id from B
>           start with
>           b_id in (#parentId#,#ids#)
>           connect by PRIOR PARENT_B_ID=B_id
>         ]]>
>   </select>
>
>   <select id="getAs" parameterClass="map"
>     resultMap="th.A">
>  ....
>         ]]>
>
> </select>
>
>
>   <resultMap id="A" class="my.A">
>     <result property="id" column="A_ID" />
>     <result property="primB" resultMap="my.PB" />
>     <result property="secBs" resultMap="my.SB" />
>     <result property="allBIds" select="getIds"/>
>   </resultMap>
>
>
> I don't know how to pass into getIds subquery PrimB and secBs can anybody
> help please?
>
> Thanks
> *
>