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 Ole Trenner <ol...@gmx.de> on 2007/08/22 10:10:20 UTC

appending to collection properties

Hello,

I understand iBatis doesn't set collection properties of java beans in
batch, but rather calls the property's getter and then adds to the
returned collection (documentation page 38: "iBATIS will repeatedly call
the get method to access the property, and then call the property's
add() method as it is processing the result set.")

That's why I tried to add to the same collection-type property of a bean
from multiple subqueries like so:

my bean:

public class Article {
    private List<ILabelled> children;
    public Article() {
        this.children = new ArrayList<ILabelled>();
    }
    public List<ILabelled> getChildren() {
        return children;
    }
    public void setChildren(List<ILabelled> children) {
        this.children = children;
    }
}

my sql map:

<resultMap class="Article" groupBy="id" id="ArticleResult">
    <result column="id" property="children"
            select="article.getCompaniesByArticle"/>
    <result column="id" property="children"
            select="article.getEventsByArticle"/>
    <result column="id" property="children"
            select="article.getArticlesByArticle"/>
</resultMap>

Each query returns objects that implement my child interface. Each one
of them by itself works perfectly. But calling all three of them as
shown above always clears the children list before adding to it.

Am I missing something? Is there an explicit way to tell iBatis to
append to my collection property?

Thanks for your help.
Cheers.
Ole.