1 min read

Mybatis Single Column Mystic

Mallim

Scenario Encountered

In the associated java interface

public boolean querySomething( @("keyField") String value )

In the mybatis xml

<select id="querySomething" parameterType="string" resultType="boolean">
select case
    when id != null then 'N'
    else 'Y'
    end IS_AFIELD
from aTable
where id = {{keyField}}
</select>

Upon selecting a non-existing id, the following error occurs:

attempted to return null from a method with a primitive return type

Solution

In Java

public Boolean querySomething( @("keyField") String value )

to ensure you are able to get the Null back and handle it accordingly