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 Heliodromel <sa...@gmail.com> on 2008/09/23 15:19:44 UTC

Sort resultset from multiple requests

Hi everybody,

i've got a question about sorting. It's maybe stupid but i can't find the
solution.

Here is my problem :

I make a simple request in a database, for example :

<select id="MyRequest" parameterClass="map" resultMap="MyRequest.result">
    select firstname, lastname, age, ref_cat from MyTable
</select>

And i got a simple resultmap, something like that :

<resultMap id="MyRequest.result">
    <result property="firstname" column="firstname" columnIndex="1"/>
    <result property="lastname" column="lastname" columnIndex="2"/>
    <result property="age" column="age" columnIndex="3"/>
    <result property="cat" column="ref_cat" columnIndex="4"
select="getCatName"/>
</resultMap>

And we consider that the request getCatName returns a resultset containing
the name and the age of the persons cat(s).

I would like to sort the persons results represented by this resutmap by the
name of the cat(s).  

Is it possible ?

Thank's for your help,

Helio.
-- 
View this message in context: http://www.nabble.com/Sort-resultset-from-multiple-requests-tp19627486p19627486.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Sort resultset from multiple requests

Posted by Heliodromel <sa...@gmail.com>.
Hi Kay,

Thanks for your answer.

Actually, the getCatName is just a example, it could be "select * from Cat"
and the table Cat would be constituted with 2 fields : a name and an age.

I had already tried to use the groupBy property but it didn't work. Actually
i was using it wrong. This morning, i tried an other time and it worked.
It's really easy to use but i don't know why i couldn't make it work...maybe
tired...;)

So here is the solution, applied to my example, for people who would have
the same problem :

For example if i want my result to be order by the name of the cats, i just
have to add a groupBy attribute in the resultMap to indicate iBatis how to
sort the result :

<resultMap id="MyRequest.result" groupBy="cat.name">
    <result property="firstname" column="firstname" columnIndex="1"/>
    <result property="lastname" column="lastname" columnIndex="2"/>
    <result property="age" column="age" columnIndex="3"/>
    <result property="cat" column="ref_cat" columnIndex="4"
select="getCatName"/>
</resultMap> 

Thanks again for your help,

Regards,

Helio.


Kai Grabfelder-2 wrote:
> 
> Hi Helio,
> 
> what does your getCatName select looks like? Can't you just use an order
> by in that select? Furthermore, you
> may want to have a look at the groupBy feature of iBATIS to avoid the n+1
> select problem.  The documentation
> [1] describes this in more detail.
> 
> Regards
> 
> Kai
> 
> [1]
> http://svn.apache.org/repos/asf/ibatis/trunk/java/ibatis-2/ibatis-2-docs/en/
> 
> 
-- 
View this message in context: http://www.nabble.com/Sort-resultset-from-multiple-requests-tp19627486p19643717.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Sort resultset from multiple requests

Posted by Kai Grabfelder <no...@kinokai.de>.
Hi Helio,

what does your getCatName select looks like? Can't you just use an order by in that select? Furthermore, you
may want to have a look at the groupBy feature of iBATIS to avoid the n+1 select problem.  The documentation
[1] describes this in more detail.

Regards

Kai

[1] http://svn.apache.org/repos/asf/ibatis/trunk/java/ibatis-2/ibatis-2-docs/en/



--- Original Nachricht ---
Absender: Heliodromel
Datum: 23.09.2008 15:19
> Hi everybody,
> 
> i've got a question about sorting. It's maybe stupid but i can't find the
> solution.
> 
> Here is my problem :
> 
> I make a simple request in a database, for example :
> 
> <select id="MyRequest" parameterClass="map" resultMap="MyRequest.result">
>     select firstname, lastname, age, ref_cat from MyTable
> </select>
> 
> And i got a simple resultmap, something like that :
> 
> <resultMap id="MyRequest.result">
>     <result property="firstname" column="firstname" columnIndex="1"/>
>     <result property="lastname" column="lastname" columnIndex="2"/>
>     <result property="age" column="age" columnIndex="3"/>
>     <result property="cat" column="ref_cat" columnIndex="4"
> select="getCatName"/>
> </resultMap>
> 
> And we consider that the request getCatName returns a resultset containing
> the name and the age of the persons cat(s).
> 
> I would like to sort the persons results represented by this resutmap by the
> name of the cat(s).  
> 
> Is it possible ?
> 
> Thank's for your help,
> 
> Helio.