Ibatis filling up Nested object in Java

463 views Asked by At

I have one java class which resembles to

class A {
  String a;
  B bclass;
}
class B {
  String b;
  String c;
}

my ibatis query is : Select a,b,c from A_TABLE and resultmap I want is something like this where I can fill properties of class B (B.b,B.c) as well.

<resultMap class="A" id="resmap">
  <result property="a"  column="A"  jdbcType="VARCHAR"/>
  <result property="bclass.b"  column="B"  jdbcType="VARCHAR"/>
  <result property="bclass.c"  column="C"  jdbcType="VARCHAR"/>
</resultmap>

any idea how I can fill this object A from ibatis query so I have all 3 a,b,c properties filled?

1

There are 1 answers

0
Chaosfire On

The mapping of inner objects is made with association tag. You need something like this:

<resultMap id="resmap" type="A">
    <result property="a" column="a"/>
    <association property="b" javaType="B">
        <result property="b" column="b"/>
        <result property="c" column="c"/>
    </association>
</resultMap>

Check documentation as well, it's explained in details.