I have an error when setting a parameter as null.
This problem ONLY occurs while using ojdbc14.jar. When using ojdbc6.jar, it is fine.
I have this setting in mybatis configuration xml
<settings>
<setting name="jdbcTypeForNull" value="NULL"/>
</settings>
The error message is:
Caused by: org.apache.ibatis.type.TypeException: Error setting null for parameter #1 with JdbcType NULL . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull
The sql in xml is
<update id="rename" parameterType="Element">
update dsb_element t set t.elementname = #{elementName} where t.elementid = #{elementId}
</update>
The java calling it is
com.my.Element ele = new Element();
ele.setElementId("some-id");
ele.setElementName(null);
sqlSession.update(getMyBatisId("rename"), element) ;
The question is:
Is it a problem of ojdbc14.jar, and if so, why?
I know I can solve it by using #{elementName, jdbcType=VARCHAR2}, but my project has lots of this problem everywhere and it is due soon. I don't want to change all of them.
The problem is that since the 3.0.x versions the default JDBC type for null parameters is Types.OTHER
which not supported by some JDBC drivers like Oracle 10g.
Here a post that explain this issue.
The solution I found is very simple, I set jdbcTypeForNull
to NULL
in the configuration file.
<configuration>
<properties resource="mybatis-config.properties" />
<settings>
<setting name="jdbcTypeForNull" value="NULL" />
</settings>
<environments default="development">
....
</environments>
<mappers>
....
</mappers>
</configuration>