-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Description
MyBatis version
- MyBatis 3.4.4
- MyBatis Spring Boot Starter 1.3.0
Database vendor and version
H2 1.4.194
Test case or example project
https://github.com/onozaty/sandbox-java/tree/master/mybatis-size-mapping-error
Steps to reproduce
I will create the following repository, call insert method. The parameter size is of type long.
package com.example.demo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@Repository
@Mapper
public interface TestRepository {
@Insert("INSERT INTO test(number, size) VALUES(#{number}, #{size})")
public void insert(@Param("number") long number, @Param("size") long size);
}Expected result
The call will succeed.
Actual result
An exception is raised.
size parameter is mapped to java.lang.Integer.
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='size', mode=IN, javaType=int, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy53.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:57)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy59.insert(Unknown Source)
...
Changing the parameter name to size2 will succeed.