You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Shawn Hinsey <Sh...@miva.com> on 2006/03/30 17:29:15 UTC
Complex property problem
Hello,
I'm having what's probably a really dumb problem with complex property
mappings. I think I may be misunderstanding part of the documentation.
I'd like to implement a complex property using a join, in order to avoid
the n+1 select problem.
Say I have three tables. Article, Category, and CategoryArticles, which
maps them in an many to many relationship.
Here're what I think the mapping files should look like.
<?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="Category" xmlns="http://ibatis.apache.org/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<resultMaps>
<resultMap class="Category" id="category-select">
<result property="Id" column="Id"/>
<result property="Name" column="Name"/>
<result property="SortOrder"
column="SortOrder"/>
<result property="Articles" column="Id"
resultMapping="Article.article"/>
</resultMap>
</resultMaps>
<statements>
<select id="selectAllCategories"
resultMap="category-select">
SELECT * FROM Category
</select>
<select id="selectCategoryById"
resultMap="category-select">
SELECT * FROM Category WHERE Id = #id#
</select>
</statements>
</sqlMap>
And
<?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="Article" xmlns="http://ibatis.apache.org/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<resultMaps>
<resultMap class="Article" id="article">
<result property="Id" column="Id"/>
<result property="Description"
column="Description"/>
<result property="Location" column="Location"/>
<result property="HarvestDate"
column="HarvestDate"/>
<result property="SortOrder"
column="SortOrder"/>
</resultMap>
</resultMaps>
<statements>
<select id="selectAllArticles" resultMap="article">
SELECT * FROM Article
</select>
<select id="selectArticleById"
extends="selectAllArticles" resultMap="article">
WHERE Id = #value#
</select>
</statements>
</sqlMap>
Executing selectAllCategories or selectCategoryById causes this
exception to be thrown:
[IndexOutOfRangeException: Location]
System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
+66
System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +104
IBatisNet.DataMapper.TypeHandlers.StringTypeHandler.GetValueByName(Resul
tProperty mapping, IDataReader dataReader) +18
What's going on that I'm missing?
Thanks,
Shawn
Shawn Hinsey | Senior Software Developer | MIVA | shawn.hinsey@miva.com
Tel: (617) 768-5220, ext. 239 | Fax: (617) 768-5221
MIVA Means Business
www.miva.com | NASDAQ:MIVA