mybatis / mybatipse

Eclipse plugin adding support for MyBatis SQL Mapper Framework.
Eclipse Public License 1.0
332 stars 91 forks source link

compilation error about the select statement located in separate mapper xml with same mapper namespace #86

Closed Prachi481992 closed 6 years ago

Prachi481992 commented 6 years ago

I'm trying to use a select statement defined in one mapper file in the association in the resultmap of another mapper xml. Both the mapper xmls have the same namespace. I'm using the fully qualified name to refer the select. But the same select is accessible by hyperlink. The code works fine at runtime. Below is the mapper file which needs to be imported:

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.abc.MybatisMapper">
    <!-- add column names only -->
    <select id="getADetails" resultType="com.abc.dto.A">
        SELECT a.id,
         a.name
        FROM
        TABEL_A
        <trim prefix="WHERE" prefixOverrides="AND | OR">
            a.id = #{id}
        </trim>
    </select>
</mapper>

Below is the mapper file which uses the select in first mapper file:

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.abc.MybatisMapper">

    <resultMap id="resultmapB" type="com.abc.dto.B">
       <result property="b_id" column="b_id" />
        <result property="b_name" column="b_name" />
        <association property="a_details" javaType="com.abc.dto.A" column="a_id" select="com.abc.MybatisMapper.getADetails" />
    </resultMap>
<!-- add column names only -->
    <select id="getBDetails" resultMap="resultmapB">
        SELECT b_id,
        b_name,
        a_id
        FROM
        TABEL_B
        <trim prefix="WHERE" prefixOverrides="AND | OR">
            b_id = #{id}
        </trim>
    </select>
</mapper>

The line in second file which declares the association gives the compilation error.

harawata commented 6 years ago

You're right. When I wrote that part, I didn't realize that it was possible to specify the same namespace in multiple XML mappers. It may take some time for me to fix it as it will require a major rewrite.

harawata commented 6 years ago

@Prachi481992 This should be fixed in 1.1.2 (let me know if it's not). Thank you for taking the time to report this!

Prachi481992 commented 6 years ago

@harawata The issue is resolved now. Thanks for the quick resolution!

harawata commented 6 years ago

Great. Thank you for your help, @Prachi481992 ! :)