You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by David McReynolds <da...@gmail.com> on 2008/11/05 17:02:42 UTC
mapping multiple collections
I am working through a simple example where I have a table called "titles"
that contains attributes about books. A title will have 1..* authors and a
title will also have 1..* editors. Joining the titles and authors was simple
enough. However, when I pull in the editors (using a join table) I found
that I need to make adjustments. The "adjustment" I used was to make the
Editor class comparable, make the Title class contain Set<Editor> editors
and tell ibatis that the java type is "java.util.TreeSet".
I don't see any obvious waste of resources since the result set itself has
to return the different combinations of authors and editors (ie 2 authors
and 3 editors equals 6 rows in the result set) and a RowHandler would have
to deal with each row anyway. Am I missing something?
public class Title
Set<Editor> editors;
. . .
Using the TreeSet in the sql map prevents duplication.
<resultMap groupBy="id" id="titleDetails"
extends="abatorgenerated_TitleResult" class="net.bookstore.persist.vo.Title"
>
<result column="pub_id" property="publisher.id" jdbcType="CHAR" />
<result column="pub_name" property="publisher.pubName" jdbcType="CHAR"
/>
<result column="address" property="publisher.address" jdbcType="CHAR" />
<result column="city" property="publisher.city" jdbcType="CHAR" />
<result column="state" property="publisher.state" jdbcType="CHAR" />
<result property="authors"
resultMap="authors.abatorgenerated_AuthorResult" column="au_id"
javaType="java.util.TreeSet"/>
<result property="editors"
resultMap="editors.abatorgenerated_EditorResult" column="ed_id"
javaType="java.util.TreeSet"/>
</resultMap>
--
dlm