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 Ti...@mcnichols.com on 2005/01/17 22:16:42 UTC

solution for N+1 selects

I'm having trouble implementing the 2.0.9 N+1 solution.  The example 
posted on the wiki deals with a groupBy relationship.  Is this the only 
situation where the fix applies?  I have a simple nested 1:M relationship 
that I would love to used this new feature with.  Presently I am using the 
old method of using a "select " parameter in the result element of my 
resultMap.  I have replaced this parameter with a "resultMap" parameter. 
Of course I have changed the SQL to join the necessary tables.  Must I 
change my query to a QueryForList and build my result manually or should I 
be able to use the same queryForObject that I was using before?  I am 
getting an executeQueryForObject returned too many results exception.
_______________________________________
Tim Hammar
Senior Programmer Analyst
McNichols Company
5501 W. Gray Street, Tampa, FL 33609-1007
P.O. Box 30300, Tampa, FL 33630-3300
Local: 813-282-3828, ext. 2419
Fax: 813-287-8387
tim.hammar@mcnichols.com
www.mcnichols.com

Re: solution for N+1 selects

Posted by Clinton Begin <cl...@gmail.com>.
Hmmm... I can see we really need good documentation around this.

By simple nature of a join, you MUST use groupBy.  Otherwise you'll
end up with too many parent objects.  You can use queryForList or
queryForObject with the solution, as long as the latter only returns a
single parent object.

Regardless, you can use the resultMap and groupBy independently as
required.  You just combine them to eliminate repeating groups for a
complex object graph.

Cheers,
Clinton




On Mon, 17 Jan 2005 16:16:42 -0500, Tim_Hammar@mcnichols.com
<Ti...@mcnichols.com> wrote:
>  
> I'm having trouble implementing the 2.0.9 N+1 solution.  The example posted
> on the wiki deals with a groupBy relationship.  Is this the only situation
> where the fix applies?  I have a simple nested 1:M relationship that I would
> love to used this new feature with.  Presently I am using the old method of
> using a "select " parameter in the result element of my resultMap.  I have
> replaced this parameter with a "resultMap" parameter.  Of course I have
> changed the SQL to join the necessary tables.  Must I change my query to a
> QueryForList and build my result manually or should I be able to use the
> same queryForObject that I was using before?  I am getting an
> executeQueryForObject returned too many results exception. 
> _______________________________________
>  Tim Hammar
>  Senior Programmer Analyst
>  McNichols Company
>  5501 W. Gray Street, Tampa, FL 33609-1007
>  P.O. Box 30300, Tampa, FL 33630-3300
>  Local: 813-282-3828, ext. 2419
>  Fax: 813-287-8387
>  tim.hammar@mcnichols.com
>  www.mcnichols.com