Composite Keys in Resultmaps

722 views
Skip to first unread message

chenrici

unread,
Apr 4, 2011, 12:16:26 PM4/4/11
to mybatis-user, christop...@apg.ch
We are trying to map a composite key / id. We have a table A (mapped
to a class A) with a composite key consisting of two columns (b, c).

public class A {
private AId aId = new AId();

public AId getAId() {
return aId;
}

public void setAId(AId aId) {
this.aId = aId;
}

// ... more properties
}

public class AId {
private Long b;
private Long c;

// getters and setters, equals and hashcode
}

We tried to map as follows:

<resultMap id="resultMapA" type="A">
<id property="aId" column="{b=b,c=c}" />
</resultMap>

But this doesn't work. In the documentation we read "To deal with
composite keys, you can specify multiple column names to pass to the
nested select statement by using the syntax
column={prop1=col1,prop2=col2}. This will cause prop1 and prop2 to be
set against the parameter object for the target nested select
statement."

We are not quite sure, what select statement is meant, specially the
dtd of id doesnt allow "select" or "resultMap". Also we saw in the
source code that resultMap.getIdResultMappings is only referenced in
NestedResultSetHandler, but are not quite sure how our scenario we
come to NestedResultSetHandler.

Any help, hints or corrections of our assumptions are greatly
appreciated.

Christoph

Goo Keun Lim

unread,
Apr 4, 2011, 8:29:49 PM4/4/11
to mybati...@googlegroups.com, christop...@apg.ch
try this. :)

> <resultMap id="resultMapA" type="A">

> <id property="aId.b" column="b" />
> <id property="aId.c" column="c" />
> </resultMap>

나의 iPhone에서 보냄

2011. 4. 5. 오전 1:16 chenrici <chhe...@gmail.com> 작성:

chenrici

unread,
Apr 5, 2011, 3:06:44 AM4/5/11
to mybatis-user
Great. That was easy ;-)

On Apr 5, 2:29 am, Goo Keun Lim <passion....@gmail.com> wrote:
> try this. :)
>
> > <resultMap id="resultMapA" type="A">
> > <id property="aId.b" column="b" />
> > <id property="aId.c" column="c" />
> > </resultMap>
>
> 나의 iPhone에서 보냄
>
> 2011. 4. 5. 오전 1:16 chenrici <chhenr...@gmail.com> 작성:
Reply all
Reply to author
Forward
0 new messages