MyBatis to call PROC with multiple IN parameters

I am trying to create a small CRUD tool, and so far every aspect (Rich Faces interface and managed Beans, validation, mySQL database, etc.) is going well, but not part of myBatis.

I'm relatively new to myBatis and constantly maintain a user guide and API, but there are still some things that just don't come together for me, and each of them is a procedure call including several IN parameters. Here is an example:

This is from the database creation scripts:

create procedure MY_FOO_PROC (IN valA VARCHAR(15), IN valB CHAR(1))
    begin
        select blah from blah where blah = valA and blah = valB etc.;
    end 

This is from MyMapper.java:

public interface MyMapper {
List<MyFooClass> getProgress (
        @Param("valA") String valueA, @Param("valB") String valueB);
}

This is from MyMapper.xml:

<select id="getProgress" parameterType="map" 
    resultMap="MyFooMap" statementType="CALLABLE">
    { call MY_FOO_PROC (
        #{valA, mode=IN, jdbcType=VARCHAR}
        #{valB, mode=IN, jdbcType=CHAR}
    )}
</select>

And finally, this is from my DAO class:

public static List<MyFooClass>
        doGetProgress (String valueA, String valueB) {
    SqlSession session = MyBatisConnectionFactory.getInstance().getSqlSessionFactory().openSession();
    EsparMapper mapper = session.getMapper(MyMapper.class);
    List<MyFooClass> listFoo = mapper.getProgress(valueA, valueB);  // line which originates exception below
    session.close();
    return listFoo;
}

Result:

### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Incorrect number of arguments for PROCEDURE dbname.MY_FOO_PROC; expected 2, got 1
### The error may involve my.package.names.getProgress-Inline
### The error occurred while setting parameters

Note that I also tried:

  • creating a POJO with the variables valA and valB and getters / seters for each,
  • parameterType="PojoClass"XML creation
  • skip session.getMapper()and instantiate PojoClass,
  • session.selectList("getProgress", pojoInstance);

(.. ).

, , , , , .

+5
1

, .

<select id="getProgress" parameterType="map" 
    resultMap="MyFooMap" statementType="CALLABLE">
    { call MY_FOO_PROC (
        #{valA, mode=IN, jdbcType=VARCHAR} , --<--- this
        #{valB, mode=IN, jdbcType=CHAR}
)} 
</select>
+4

All Articles