MyBatis version

3.3.1

Database vendor and version

Test case or example project

public interface BlogMapper {
     Blog selectBlog(@Param("id") int id);
}

<resultMap id="blogResult" type="Blog">
    <constructor>
        <idArg column="id" javaType="int"/>
    </constructor>
    <result property="title" column="title"/>
    <association property="author" javaType="Author"
                 resultSet="authors" column="author_id" foreignColumn="id">
        <id property="id" column="id"/>
        <result property="username" column="username"/>
        <result property="password" column="password"/>
        <result property="email" column="email"/>
    </association>
</resultMap>

<select id="selectBlog" resultSets="blogs,authors"
        resultMap="blogResult" statementType="CALLABLE">
    <![CDATA[
     {call get_blogs_and_authors(#{id,jdbcType=INTEGER,mode=IN})}
    ]]>

DELIMITER $$ CREATE PROCEDURE get_blogs_and_authors(IN ID INT) BEGIN SELECT * FROM blog WHERE id = 1; SELECT * FROM author WHERE id =1; END$$ DELIMITER ;

Steps to reproduce

Blog blog=blogMapper.selectBlog(1);

Expected result

Actual result

org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3

Comment From: gravin

SORRY, its store procedure issue, because column name is also ID as parameter ID, so mysql confused. close this issue.

drop procedure get_blogs_and_authors; DELIMITER $$ CREATE DEFINER=root@% PROCEDURE get_blogs_and_authors(IN ID INT) BEGIN SELECT * FROM blog a WHERE a.id = ID; SELECT * FROM author b WHERE b.id IN(select c.author_id from blog c where c.id=ID); END$$ DELIMITER ;