You would have to create a select that joins all children and returns
them in one shot.

Niels

-----Original Message-----
From: Ole Trenner [mailto:[EMAIL PROTECTED] 
Sent: woensdag 22 augustus 2007 10:10
To: [email protected]
Subject: 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.

Reply via email to