ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: N+1 Select with child elements stored in a map, not a list
Date Sat, 13 Aug 2005 14:31:53 GMT
I understand the problem. Unfortunately there's no easy way to do that at 
this time. You can probably implement something yourself by putting both a 
list property and a map property on your class...the map property being 
derived from the value of the list property. Both delegate to the same data, 
but one organizes it using a map, and the other using a list.

Not the answer you were looking for, but probably a simple and effective 


On 8/11/05, Brian Yoffe <byoffe@houston.rr.com> wrote:
> Ok,
> Best way to frame my question is in the context of the example on the wiki
> example located at:
> http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+get+a
> round+the+N+Plus+1+selects+problem%3F
> Now, I'm focusing on the part with the following text:
> When you call
> List myList = executeQueryForList("Calendar.getQuartersForServiceYear",
> 2005);
> , the main query is executed, and the results are stored in the {myList}
> variable as beans of type "calendarQuarter" (an alias). Each object in 
> that
> List will have a "months" property that is also a List populated from the
> same query, but using the "monthMap" result map to populate the beans in 
> the
> child lists. So, you end up with a list containing sub-lists, and only one
> database query is executed.
> So far, so good. Now, here is what I'd like to do - I want my the
> calendarQuarter objects to contain a map of months, not a list of months.
> In this cast, lets say each month is hashed by it's name. This would
> enable me to write code such as:
> calendarQuarter = (CalendarQuarter)
> executeQueryForMap("Calendar.getQuartersForServiceYear",
> 2005,"name").get("Q1");
> month = (Month) calendarQuarter.getMonths().get("January");
> I'll admit, the example is a bit contrived, but it's within a
> problem/example that I hope people are familiar with. As a better
> description of what I'm attempting to do, let's say I want to prime a 
> cache
> of data, and in this case I'm caching 1000 "parent" objects. Each "parent"
> object has 100 "child" objects associated with it. I would like to
> organize my data in memory so that I have a hash of parent objects, and 
> each
> parent object has a hash of child objects.
> If you need further clarification of the problem, I'll gladly provide it.
> Thanks

View raw message