Search code examples
javaspringmodel-view-controllermybatis

MyBatis: Attempted to return null from a method with a primitive return type


My DB connection is with mybatis, I have DAO with this function:

public int getUpdateTaskStateStart(Task task);

And the implemention is located in XML file:

<select id="getUpdateTaskStateStart" resultType="Integer" parameterType="com.ladpc.mobile.entities.Task">

        SELECT START_UPDATE
        FROM UPDATE_TASK_STATE
            WHERE 
        TASK_ID = #{taskId} AND RASHUT_ID=#{rashutId} 

    </select>

In DB, I have table UPDATE_TASK_STATE, that include START_UPDATE filed.

My problem is that when I run getUpdateTaskStateStart(Task) (and send task param that include rashutId="248" and taskId="2449" fileds inside), I get Error:

org.apache.ibatis.binding.BindingException: Mapper method 'com.ladpc.mobile.dao.AssesmentTasksDao.getUpdateTaskStateStart attempted to return null from a method with a primitive return type (int).

What is wrong with my function? Thanks!


Solution

  • Your Mapper XML specifies resultType="Integer", but getUpdateTaskStateTask() wants to return a primitive int, not the Integer wrapper class.

    Change it to resultType="int".