Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return value Mybatis

I'm trying to get a returned value (an Integer value) from a stored function in Oracle 11g.

The function adds 10 to the input number:

FUNCTION ADD_TEN(INPUT IN NUMBER) RETURN NUMBER IS 
BEGIN 
    RETURN INPUT + 10; 
END;

In my mapper interface I have the line:

Integer add(Integer input); 

And in Xml file

<select id="add" statementType="CALLABLE" resultType='java.lang.Integer'>
    {#{output,mode=OUT,jdbcType=NUMERIC,javaType=Integer} = call test_pkg.ADD_TEN( 
    #{input,jdbcType=NUMERIC}) } 
</select>`

The call to the method is like:

Integer sum = mapper.add(45); 

But I'm getting the following error:

Could not set property 'output' of 'class java.lang.Integer' with value '55' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'output' in 'class java.lang.Integer' 

What am I doing wrong? I'm really lost with this...

Thank you.

like image 835
Charles Avatar asked Dec 21 '12 11:12

Charles


People also ask

What is difference between iBATIS and MyBatis?

MyBatis is a fork from iBATIS, and according to Wikipedia most of iBATIS' developers moved over to MyBatis too. The iBATIS project is currently marked as Inactive, therefore you should go with MyBatis for new projects and only use iBATIS if you're maintaining an existing project which already uses iBATIS.

What is MyBatis in spring boot?

MyBatis is a SQL mapping framework with support for custom SQL, stored procedures, and advanced mapping. Although SpringBoot does not officially support MyBatis, the MyBatis community has created a SpringBoot startup for MyBatis.

What is resultMap in MyBatis?

The resultMap element is the most important and powerful element in MyBatis. It's what allows you to do away with 90% of the code that JDBC requires to retrieve data from ResultSet s, and in some cases allows you to do things that JDBC does not even support.


1 Answers

Why you haven't defined both parameterType and resultType like this:

parameterType="int" resultType="int"

Remove specific output and try to make it like this:

<select id="add" parameterType="int" resultType="int" statementType="CALLABLE">
    { CALL ADD_TEN(#{input, mode=IN, jdbcType=INTEGER})}
</select>
like image 105
Igor Konoplyanko Avatar answered Oct 14 '22 05:10

Igor Konoplyanko