You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by "vinay.a" <vi...@yahoo.com> on 2009/05/25 15:15:54 UTC

Achieving Group By feature.

Hello all,

I need some help on the below scenario:

I have 2 business objects. Lets say 'University' and 'College'.
The 'University' object has the following property.

public IList<College> collegelist
{
get;
set;
}

Now I want to execute a query that groups all the Colleges which come under
an University, and store the result in the University Object.
This way I will have one 'University' object (with university details),
within which i will have an IList<College> with all the details of all the
colleges under that university.

Is it possible to achieve this using a query and object mapping in
ibatis.net
If not possible, please let me know.

Thanks and regards,
Vinay A
-- 
View this message in context: http://www.nabble.com/Achieving-Group-By-feature.-tp23706884p23706884.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.


Re: Achieving Group By feature.

Posted by Juan Pablo Araya <ju...@gmail.com>.
Under de assumption that you just use the select property in the <result
property> for University.CollegeList, you have something like this:

List<Univ> universities = ibatis.FindUniversities();
foreach (Univ item in universities)
 item.CollegeList = ibatis.FindCollegeListByUnivId(item.Id);

* one query for all the univs, one query for the collegeList foreach univ =
101 queries

If it's much, you can use lazyload. With this, the college queries are
executed just when needed (see 3.5.4.9 from the manual)




On Tue, May 26, 2009 at 12:46 AM, vinay.a <vi...@yahoo.com> wrote:

>
> I need some clarification on how iBatis.net executes the queries in the
> 'University-College' scenario.
> Assuming that there are 100 Universities and each University may have about
> 2-3 Colleges registered under it.
> So, in this case how many hits will be there to the database.
> And can i find any documentation or articles to understand this.
>
> thanks and regards,
> vinay
>
>
>
>
>
> vinay.a wrote:
> >
> > Hello all,
> >
> > I need some help on the below scenario:
> >
> > I have 2 business objects. Lets say 'University' and 'College'.
> > The 'University' object has the following property.
> >
> > public IList<College> collegelist
> > {
> > get;
> > set;
> > }
> >
> > Now I want to execute a query that groups all the Colleges which come
> > under an University, and store the result in the University Object.
> > This way I will have one 'University' object (with university details),
> > within which i will have an IList<College> with all the details of all
> the
> > colleges under that university.
> >
> > Is it possible to achieve this using a query and object mapping in
> > ibatis.net
> > If not possible, please let me know.
> >
> > Thanks and regards,
> > Vinay A
> >
>
> --
> View this message in context:
> http://www.nabble.com/Achieving-Group-By-feature.-tp23706884p23716770.html
> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>
>

Re: Achieving Group By feature.

Posted by "vinay.a" <vi...@yahoo.com>.
I need some clarification on how iBatis.net executes the queries in the
'University-College' scenario.
Assuming that there are 100 Universities and each University may have about
2-3 Colleges registered under it.
So, in this case how many hits will be there to the database.
And can i find any documentation or articles to understand this.

thanks and regards,
vinay





vinay.a wrote:
> 
> Hello all,
> 
> I need some help on the below scenario:
> 
> I have 2 business objects. Lets say 'University' and 'College'.
> The 'University' object has the following property.
> 
> public IList<College> collegelist
> {
> get;
> set;
> }
> 
> Now I want to execute a query that groups all the Colleges which come
> under an University, and store the result in the University Object.
> This way I will have one 'University' object (with university details),
> within which i will have an IList<College> with all the details of all the
> colleges under that university.
> 
> Is it possible to achieve this using a query and object mapping in
> ibatis.net
> If not possible, please let me know.
> 
> Thanks and regards,
> Vinay A
> 

-- 
View this message in context: http://www.nabble.com/Achieving-Group-By-feature.-tp23706884p23716770.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.


Re: Achieving Group By feature.

Posted by "vinay.a" <vi...@yahoo.com>.
I went through the section "3.5.12. Complex collection properties" as
specified by you.
Its neat and working fine.

Thanks and regards,
Vinay =)
-- 
View this message in context: http://www.nabble.com/Achieving-Group-By-feature.-tp23706884p23708619.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.


Re: Achieving Group By feature.

Posted by Juan Pablo Araya <ju...@gmail.com>.
See "3.5.12. Complex collection properties" in
http://ibatis.apache.org/docs/dotnet/datamapper/ch03s05.html

On Mon, May 25, 2009 at 9:31 AM, Juan Pablo Araya <juanpablo.araya@gmail.com
> wrote:

> Use in the resultmap:
> <resultmap id="UniversityResult" class="University">
> ....
> <result property  = "collegelist" column="UNIVERSITY_ID" select
> ="selectCollegeByUniversityId"/>
> ...
> </resultmap>
>
> and then create a statement called "selectCollegeByUniversityId"
>
> <select id="selectCollegeByUniversityId" parameterClass="Int32"
> resultMap="the-CollegeResultMapping">
> select * from college where univ_id = #value#
> </select>
>
> Greetings!
>
>
> On Mon, May 25, 2009 at 9:15 AM, vinay.a <vi...@yahoo.com> wrote:
>
>>
>> Hello all,
>>
>> I need some help on the below scenario:
>>
>> I have 2 business objects. Lets say 'University' and 'College'.
>> The 'University' object has the following property.
>>
>> public IList<College> collegelist
>> {
>> get;
>> set;
>> }
>>
>> Now I want to execute a query that groups all the Colleges which come
>> under
>> an University, and store the result in the University Object.
>> This way I will have one 'University' object (with university details),
>> within which i will have an IList<College> with all the details of all the
>> colleges under that university.
>>
>> Is it possible to achieve this using a query and object mapping in
>> ibatis.net
>> If not possible, please let me know.
>>
>> Thanks and regards,
>> Vinay A
>> --
>> View this message in context:
>> http://www.nabble.com/Achieving-Group-By-feature.-tp23706884p23706884.html
>> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>>
>>
>

Re: Achieving Group By feature.

Posted by Juan Pablo Araya <ju...@gmail.com>.
Use in the resultmap:
<resultmap id="UniversityResult" class="University">
....
<result property  = "collegelist" column="UNIVERSITY_ID" select
="selectCollegeByUniversityId"/>
...
</resultmap>

and then create a statement called "selectCollegeByUniversityId"

<select id="selectCollegeByUniversityId" parameterClass="Int32"
resultMap="the-CollegeResultMapping">
select * from college where univ_id = #value#
</select>

Greetings!

On Mon, May 25, 2009 at 9:15 AM, vinay.a <vi...@yahoo.com> wrote:

>
> Hello all,
>
> I need some help on the below scenario:
>
> I have 2 business objects. Lets say 'University' and 'College'.
> The 'University' object has the following property.
>
> public IList<College> collegelist
> {
> get;
> set;
> }
>
> Now I want to execute a query that groups all the Colleges which come under
> an University, and store the result in the University Object.
> This way I will have one 'University' object (with university details),
> within which i will have an IList<College> with all the details of all the
> colleges under that university.
>
> Is it possible to achieve this using a query and object mapping in
> ibatis.net
> If not possible, please let me know.
>
> Thanks and regards,
> Vinay A
> --
> View this message in context:
> http://www.nabble.com/Achieving-Group-By-feature.-tp23706884p23706884.html
> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>
>