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 Babitha <Ba...@ge.com> on 2009/06/01 14:39:29 UTC

Populate List within object in iBatis

Hi,

I have a Dealer bean. The Dealer bean contains a List of DealerContact bean
objects. I would have to execute 2 select queries to populate Dealer bean
and DealerContact bean. I wish to execute both the select queries in one go,
such that all the details of Dealer bean including DealerContact property
gets populated. But my DealerContact list returns null.

I have attached the Dealer bean, DealerContact bean and the xml file
containing the queries. Please help me in finding out where I am going
wrong.

I am making the iBatis call using the below code:

List dealerDetailsList =
getSqlMapClientTemplate().queryForList("selectDealerDetails", dealer); 

Thanks in advance for the help extended.

- Babitha http://www.nabble.com/file/p23814348/sqlDatabaseQueries.xml
sqlDatabaseQueries.xml  http://www.nabble.com/file/p23814348/Dealer.java
Dealer.java  http://www.nabble.com/file/p23814348/DealerContact.java
DealerContact.java 
-- 
View this message in context: http://www.nabble.com/Populate-List-within-object-in-iBatis-tp23814348p23814348.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Populate List within object in iBatis

Posted by Vadim <de...@gmail.com>.
Well, joins, being the primary operation supported by relation databases,
shouldn't cause you much trouble. Especially if you join on primary key. If
you don't, and your application doesn't belong to most apps where joining
two tables is a non-issue, proper indexing (after you've done some analysis
on why your query is slow) will certainly help.

If it doesn't -- you've still got a lot of choices which I won't cover here.

On Tue, Jun 2, 2009 at 9:57 AM, Babitha <Ba...@ge.com> wrote:

>
> Thanks Alin. The solution worked. :)
>
> But I was just wondering if applying a join on the 2 tables would be okay.
> If i have to fetch quite a number of fields, then wouldn't the join be a
> performance issue?
>
> Regards,
> Babitha
>
>
> Alin Popa wrote:
> >
> > Hi Babitha,
> >
> > Hopefully that I understand right your issue, so, here is how I made it
> > (and
> > I think also this is the iBatis way to handle it)
> >
> > <sqlMap namespace="MyObject">
> >
> >     <resultMap id="result" class="org.test.MyObject" groupBy="id">
> >         <result property="id" column="id" columnIndex="1" />
> >         <result property="name" column="name" columnIndex="2" />
> >         <result property="details" column="details" columnIndex="3" />
> >         <result property="properties" resultMap="MyObject.resultProperty"
> > />
> >     </resultMap>
> >
> >     <resultMap class="org.test.Property" id="resultProperty">
> >         <result property="objId" column="obj_id" />
> >         <result property="name" column="property_name" />
> >         <result property="value" column="property_value" />
> >     </resultMap>
> >
> >     <select id="getMyObjects" resultMap="result"
> > parameterClass="java.util.Map">
> >         SELECT obj.id as id, obj.name, obj.details, p.id as property_id,
> > p.obj_id as obj_id, p.name as property_name, p.value as property_value
> >         FROM objects obj LEFT JOIN properties p
> >         ON obj.id = p.obj_id WHERE obj.id=#id#
> >     </select>
> >
> > </sqlMap>
> >
> >
> >
> > On Mon, Jun 1, 2009 at 3:39 PM, Babitha <Ba...@ge.com> wrote:
> >
> >>
> >> Hi,
> >>
> >> I have a Dealer bean. The Dealer bean contains a List of DealerContact
> >> bean
> >> objects. I would have to execute 2 select queries to populate Dealer
> bean
> >> and DealerContact bean. I wish to execute both the select queries in one
> >> go,
> >> such that all the details of Dealer bean including DealerContact
> property
> >> gets populated. But my DealerContact list returns null.
> >>
> >> I have attached the Dealer bean, DealerContact bean and the xml file
> >> containing the queries. Please help me in finding out where I am going
> >> wrong.
> >>
> >> I am making the iBatis call using the below code:
> >>
> >> List dealerDetailsList =
> >> getSqlMapClientTemplate().queryForList("selectDealerDetails", dealer);
> >>
> >> Thanks in advance for the help extended.
> >>
> >> - Babitha http://www.nabble.com/file/p23814348/sqlDatabaseQueries.xml
> >> sqlDatabaseQueries.xml
> http://www.nabble.com/file/p23814348/Dealer.java
> >> Dealer.java  http://www.nabble.com/file/p23814348/DealerContact.java
> >> DealerContact.java
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Populate-List-within-object-in-iBatis-tp23814348p23814348.html
> >> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Regards,
> >
> > Alin
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Populate-List-within-object-in-iBatis-tp23814348p23827424.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: Populate List within object in iBatis

Posted by Babitha <Ba...@ge.com>.
Thanks Alin. The solution worked. :)

But I was just wondering if applying a join on the 2 tables would be okay.
If i have to fetch quite a number of fields, then wouldn't the join be a
performance issue?

Regards,
Babitha


Alin Popa wrote:
> 
> Hi Babitha,
> 
> Hopefully that I understand right your issue, so, here is how I made it
> (and
> I think also this is the iBatis way to handle it)
> 
> <sqlMap namespace="MyObject">
> 
>     <resultMap id="result" class="org.test.MyObject" groupBy="id">
>         <result property="id" column="id" columnIndex="1" />
>         <result property="name" column="name" columnIndex="2" />
>         <result property="details" column="details" columnIndex="3" />
>         <result property="properties" resultMap="MyObject.resultProperty"
> />
>     </resultMap>
> 
>     <resultMap class="org.test.Property" id="resultProperty">
>         <result property="objId" column="obj_id" />
>         <result property="name" column="property_name" />
>         <result property="value" column="property_value" />
>     </resultMap>
> 
>     <select id="getMyObjects" resultMap="result"
> parameterClass="java.util.Map">
>         SELECT obj.id as id, obj.name, obj.details, p.id as property_id,
> p.obj_id as obj_id, p.name as property_name, p.value as property_value
>         FROM objects obj LEFT JOIN properties p
>         ON obj.id = p.obj_id WHERE obj.id=#id#
>     </select>
> 
> </sqlMap>
> 
> 
> 
> On Mon, Jun 1, 2009 at 3:39 PM, Babitha <Ba...@ge.com> wrote:
> 
>>
>> Hi,
>>
>> I have a Dealer bean. The Dealer bean contains a List of DealerContact
>> bean
>> objects. I would have to execute 2 select queries to populate Dealer bean
>> and DealerContact bean. I wish to execute both the select queries in one
>> go,
>> such that all the details of Dealer bean including DealerContact property
>> gets populated. But my DealerContact list returns null.
>>
>> I have attached the Dealer bean, DealerContact bean and the xml file
>> containing the queries. Please help me in finding out where I am going
>> wrong.
>>
>> I am making the iBatis call using the below code:
>>
>> List dealerDetailsList =
>> getSqlMapClientTemplate().queryForList("selectDealerDetails", dealer);
>>
>> Thanks in advance for the help extended.
>>
>> - Babitha http://www.nabble.com/file/p23814348/sqlDatabaseQueries.xml
>> sqlDatabaseQueries.xml  http://www.nabble.com/file/p23814348/Dealer.java
>> Dealer.java  http://www.nabble.com/file/p23814348/DealerContact.java
>> DealerContact.java
>> --
>> View this message in context:
>> http://www.nabble.com/Populate-List-within-object-in-iBatis-tp23814348p23814348.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Regards,
> 
> Alin
> 
> 

-- 
View this message in context: http://www.nabble.com/Populate-List-within-object-in-iBatis-tp23814348p23827424.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Suggest that "resultMap" add a "ignoreNotExists" attribute.

Posted by Larry Meadors <la...@gmail.com>.
Easy route:

<select id="s1" resultMap="xresult">
         select a, b, null as c from x
</select>

If you feel really, really strongly that it is added, get the source
from svn and do so. :-)

Larry


On Thu, Jun 18, 2009 at 5:41 AM, joson yu<yu...@gmail.com> wrote:
> hi liangfei:
>  i meet a situation,just like your example,i need to use the same resultmap
> with the two query. and currently ,is there any way to attain the aim.
>
> 2009/6/2 liangfei <li...@gmail.com>
>>
>> Suggest that "resultMap" add a "ignoreNotExists" attribute:
>>
>>
>>
>> <resultMap id="xresult" class="xclass" ignoreNotExists="true">
>>
>>          <result property="a" column="a" />
>>
>>          <result property="b" column="b" />
>>
>>          <result property="c" column="c" />
>>
>>          <result property="d" column="d" />
>>
>> </resultMap>
>>
>>
>>
>> <select id="s1" resultMap="xresult">
>>
>>          select a, b from x
>>
>> </select>
>>
>>
>>
>> <select id="s2" resultMap="xresult">
>>
>>          select a, b, c from x
>>
>> </select>
>>
>>
>

Re: Suggest that "resultMap" add a "ignoreNotExists" attribute.

Posted by joson yu <yu...@gmail.com>.
hi liangfei:
 i meet a situation,just like your example,i need to use the same resultmap
with the two query. and currently ,is there any way to attain the aim.

2009/6/2 liangfei <li...@gmail.com>

>  Suggest that "resultMap" add a "ignoreNotExists" attribute:
>
>
>
> <resultMap id="xresult" class="xclass" ignoreNotExists="true">
>
>          <result property="a" column="a" />
>
>          <result property="b" column="b" />
>
>          <result property="c" column="c" />
>
>          <result property="d" column="d" />
>
> </resultMap>
>
>
>
> <select id="s1" resultMap="xresult">
>
>          select a, b from x
>
> </select>
>
>
>
> <select id="s2" resultMap="xresult">
>
>          select a, b, c from x
>
> </select>
>
>
>

Suggest that "resultMap" add a "ignoreNotExists" attribute.

Posted by liangfei <li...@gmail.com>.
Suggest that "resultMap" add a "ignoreNotExists" attribute:

 

<resultMap id="xresult" class="xclass" ignoreNotExists="true">

         <result property="a" column="a" />

         <result property="b" column="b" />

         <result property="c" column="c" />

         <result property="d" column="d" />

</resultMap>

 

<select id="s1" resultMap="xresult">

         select a, b from x

</select>

 

<select id="s2" resultMap="xresult">

         select a, b, c from x

</select>

 


Re: Populate List within object in iBatis

Posted by Alin Popa <al...@gmail.com>.
Hi Babitha,

Hopefully that I understand right your issue, so, here is how I made it (and
I think also this is the iBatis way to handle it)

<sqlMap namespace="MyObject">

    <resultMap id="result" class="org.test.MyObject" groupBy="id">
        <result property="id" column="id" columnIndex="1" />
        <result property="name" column="name" columnIndex="2" />
        <result property="details" column="details" columnIndex="3" />
        <result property="properties" resultMap="MyObject.resultProperty" />
    </resultMap>

    <resultMap class="org.test.Property" id="resultProperty">
        <result property="objId" column="obj_id" />
        <result property="name" column="property_name" />
        <result property="value" column="property_value" />
    </resultMap>

    <select id="getMyObjects" resultMap="result"
parameterClass="java.util.Map">
        SELECT obj.id as id, obj.name, obj.details, p.id as property_id,
p.obj_id as obj_id, p.name as property_name, p.value as property_value
        FROM objects obj LEFT JOIN properties p
        ON obj.id = p.obj_id WHERE obj.id=#id#
    </select>

</sqlMap>



On Mon, Jun 1, 2009 at 3:39 PM, Babitha <Ba...@ge.com> wrote:

>
> Hi,
>
> I have a Dealer bean. The Dealer bean contains a List of DealerContact bean
> objects. I would have to execute 2 select queries to populate Dealer bean
> and DealerContact bean. I wish to execute both the select queries in one
> go,
> such that all the details of Dealer bean including DealerContact property
> gets populated. But my DealerContact list returns null.
>
> I have attached the Dealer bean, DealerContact bean and the xml file
> containing the queries. Please help me in finding out where I am going
> wrong.
>
> I am making the iBatis call using the below code:
>
> List dealerDetailsList =
> getSqlMapClientTemplate().queryForList("selectDealerDetails", dealer);
>
> Thanks in advance for the help extended.
>
> - Babitha http://www.nabble.com/file/p23814348/sqlDatabaseQueries.xml
> sqlDatabaseQueries.xml  http://www.nabble.com/file/p23814348/Dealer.java
> Dealer.java  http://www.nabble.com/file/p23814348/DealerContact.java
> DealerContact.java
> --
> View this message in context:
> http://www.nabble.com/Populate-List-within-object-in-iBatis-tp23814348p23814348.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>


-- 
Regards,

Alin