使用第二范式数据库规范化时的Mybatis映射器

时间:2014-12-10 09:04:27

标签: orm mybatis ibatis database-normalization

我有一种情况需要使用mybatis,我们使用第二种规范化形式。例如,我提到两个表 Table_One Table_Two ,其PK在表 Table_Key 中。现在我尝试将这些映射到POJO,其中如下所示,类为 ClassOne ClassTwo 。问题是我无法在此处获取 rel_data rel_user 列,因为我没有在任何一个POJO中为这些列创建任何字段第一和第二类/表。

据我所知,mybatis不是ORM技术,更像是数据映射层。如果是这样,我是否需要为关系表创建另一个POJO以获取此表中的数据?

Table_One {
    one_key,
    one_desc
    :
    :
}

Table_Two{
    two_key,
    two_desc
    :
    :
}

Table_Key{
    one_key,
    two_key,
    rel_date,
    rel_user
}

ClassOne{
    private String oneKey;
    private String oneDesc;
    private ClassTwo classTwo;
    //getter setter
}

ClassTwo{
    private String twoKey;
    private String twoDesc;
    //getter setter
}

<resultMap type="One" id="oneResultMap">
        <id column="one_key" property="id" />
        <result column="one_desc" property="Desc" />
        <association property="two" resultMap="twoResultMap"/>
</resultMap>

<resultMap type="Two" id="twoResultMap">
        <id column="two_key" property="id" />
        <result column="two_desc" property="Desc" />
</resultMap>

0 个答案:

没有答案