ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Jenkins <krisajenk...@yahoo.co.uk>
Subject Re: What is N+1
Date Wed, 09 Feb 2005 12:28:43 GMT

>Well, I think you need only simple join in your sql, no extra features of
>ibatis needed:
>select * from CHILD, PARENT where parent_id=PARENT.id;
>am I right?
>
Well, that's the right query, but only if you use groupBy.  Assuming 
you're trying to get Parent objects populated with their correct Child 
objects, you query will return something like:

parent_id | child_id
----------+---------
1         | a
1         | b
1         | c
2         | d

Without groupBy in your resultMap, you'll end up with 3 parent objects, 
each with one child.  What you wanted was 2 parents, one with three 
children.

So you're right, groupBy allows you to do this with one query, but 
before v2.0.9 you'd've needed two separate ones to get the right result.

Kris

-- 
Kris Jenkins
Email:  kris@jenkster.com
Blog:   http://cafe.jenkster.com/
Wiki:   http://wiki.jenkster.com/



Mime
View raw message