New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the parameter name is "size", it is always mapped with integer #1030

Closed
onozaty opened this Issue Jun 10, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@onozaty

onozaty commented Jun 10, 2017

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.

@kazuki43zoo

This comment has been minimized.

Show comment
Hide comment
@kazuki43zoo

kazuki43zoo Jun 11, 2017

Member

@onozaty Thanks for your report!!

MyBatis use the HashMap#size instead of @Param("size") long size in this case.

Member

kazuki43zoo commented Jun 11, 2017

@onozaty Thanks for your report!!

MyBatis use the HashMap#size instead of @Param("size") long size in this case.

@kazuki43zoo kazuki43zoo self-assigned this Jun 11, 2017

@kazuki43zoo kazuki43zoo added the bug label Jun 11, 2017

kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jun 11, 2017

kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jun 11, 2017

kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jun 11, 2017

kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jun 11, 2017

@kazuki43zoo kazuki43zoo closed this in #1031 Jun 11, 2017

kazuki43zoo referenced this issue Jun 11, 2017

Merge pull request #1031 from kazuki43zoo/gh-1030
Allow long type on size parameter when use multiple '@param'

@kazuki43zoo kazuki43zoo added this to the 3.4.5 milestone Jun 11, 2017

@kazuki43zoo

This comment has been minimized.

Show comment
Hide comment
@kazuki43zoo

kazuki43zoo Jun 11, 2017

Member

@onozaty I've fixed this. You can use the 3.4.5-SNAPSHOT for applying this fix.

Member

kazuki43zoo commented Jun 11, 2017

@onozaty I've fixed this. You can use the 3.4.5-SNAPSHOT for applying this fix.

@onozaty

This comment has been minimized.

Show comment
Hide comment
@onozaty

onozaty Jul 2, 2017

@kazuki43zoo Thank you! I confirm the 3.4.5-SNAPSHOT.

onozaty commented Jul 2, 2017

@kazuki43zoo Thank you! I confirm the 3.4.5-SNAPSHOT.

@kazuki43zoo kazuki43zoo removed this from the 3.4.5 milestone Jul 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment