ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Perry Nguyen <pfngu...@hanhuy.com>
Subject Re: N+1 solution and queryForList(String, Object, int, MAX)
Date Sat, 17 Dec 2005 00:24:48 GMT

It looks like I can handle this situation with a RowHandler, but how can
I implement the MAX condition within a RowHandler as it seems the 
interface does not offer any way to stop parsing the result set.

I currently have a workaround in which I simply throw a RuntimeException 
from within my handler and catch the SQLException that 
queryWithRowHandler throws.

This works, for now, but it seems like such an ugly solution...  Is 
there an "approved" method of stopping a RowHandler?

Perry Nguyen wrote:
> When using the iBATIS N+1 solution and the max parameter in 
> queryForList, the behavior is a little bit different than what I would 
> expect.
> The max parameter appears to only address the total rows returned, 
> however and not the number of elements that would be populated into the 
> return List.
> E.g.
> I have a table:
> products (
>   id
>   name
> )
> product_attributes (
>   prod_id,
>   name,
>   value
> )
> With a query like:
> select p.id, p.name, a.name, a.value
> from products p, product_attributes a
> If there are 30 attributes to a single product and I specify the max 
> results to only be 15,  I don't get 15 product objects in my List, but 
> rather a single product object with 15 attributes populated.
> This behavior is quite misleading as I would expect to retrieve 15 
> product objects.  Is there any workaround to this?  Does anything depend 
> on the existing behavior?  Can it be changed to support my desired 
> behavior?

View raw message