I'm trying to design a small CRUD tool, and so far every facet (the Rich Faces UI and Managed Beans, validation, the mySQL database, etc.) is going fine, but not the myBatis piece.
I'm relatively new to myBatis and am keeping the users guide and API close at hand, but there are still some things that just won't come together for me, and one is any call to a procedure involving multiple IN parameters. Here is an example:
This from the DB set up 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 from MyMapper.java:
public interface MyMapper {
List<MyFooClass> getProgress (
@Param("valA") String valueA, @Param("valB") String valueB);
}
This 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 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;
}
The 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
I will note that I have also tried:
parameterType="PojoClass"
in the XML,session.getMapper()
and creating an instance of PojoClass,session.selectList("getProgress", pojoInstance);
with the nearly identical result (i.e. wrong number of arguments).
Very little help on net search, most telling me to do what I think I have already done.
Unlike IBATIS, there is no <procedure> tag in MyBatis. To map the results of the procedures, we have created a resultmap named Student and to call the stored procedure named read_recordById. We have defined a select tag with id callById, and we use the same id in the application to call the procedure.
For an easiest query. Not considering the first query, for the following queries, JDBC always takes about 6ms~10ms, and MyBatis takes about 31~35ms, which is about 3 times. For a more complex query (6 inner joins and an order by in it), JDBC only takes 25~30ms, while MyBatis needs 80~100ms.
NOTE You can pass any Iterable object (for example List, Set, etc.), as well as any Map or Array object to foreach as collection parameter.
I think you're missing a comma in the procedure call.
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With