ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Dominic.Ster...@bedag.ch>
Subject Select n+1 Problem
Date Thu, 18 Aug 2005 13:08:34 GMT
Hi

Concerning the developer guide, it is possible to avoid the select n+1
problem
I have something like this:
Java:
Class Category{
	String name;
	Collection itemList;
	
	public void setItemList(Collection _itemList) {
		this.itemList = _itemList;
	}	
	public void setName(String _name){
		this.name=name;
	}
	...
}

Class Item{
	String name;
	public void setName(String _Name){
		this.name=_name;
	}	
	....
}

Database:
Table Category:
Id	name
1	Apple
2	Microsoft

Table Item:
Id	CategoryFk	name
1	1		OS X
2	1		iLife
3	2		whatever
4	2		worse whatever

Question:
I don't see how I can avoid to make for each category a select to the
item table.

(like this):
	List list = sqlMap.queryForList("getCategory",null);
	for (Iterator iter = list.iterator(); iter.hasNext();) {
		Category category=(Category)iter.next();
		List itemList = sqlMap.queryForList("getItem",new
Integer(category.getId));
		category.setItemList(itemList);
	}
I didn't fully understand  the Calendar sample in the developer guide. 
TIA Dominic

Mime
View raw message