ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Yoffe" <byo...@houston.rr.com>
Subject N+1 Select with child elements stored in a map, not a list
Date Thu, 11 Aug 2005 23:36:13 GMT
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


Mime
View raw message