MyBatis version

since 3.4.1

Test case or example project

<insert id="setProperty">
    REPLACE INTO ServerProperties(`name`, `value`) VALUES (#{0}, #{1})
</insert>

void setProperty(String key, String value);

useActualParamName was not explicitely set.

Actual result

Exception is thrown: org.apache.ibatis.binding.BindingException: Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]

Expected result

Should work without errors. It would be nice to retain backward compatibility.

Description

I was migrarting our project from MyBatis 3.3 to MyBatis 3.4.5. And it started to fail in multiple requests, becaues we often used positioning parameters like #{0}

After some investigations, I found, that in #549 (MyBatis 3.4.1) a new parameter useActualParamName was introduced with the default value true. That is why ParamNameResolver uses parameter names which are either arg0, arg1 or correct names if -parameters is specified, but non old-fashioned 0, 1. This breaks the backward compatibility.

It would be nice to still support old positioning by default to retain the backward compatibility. I suggest to add positioning params 0, 1 along with param1, param2 near ParamNameResolver.java:126.

Comment From: vbolshutkin

Workaround is to explicitely set useActualParamName to false. Or refactor all the requests to use param1, param2, @Param or Java8 named parameters.

Comment From: harawata

Hi @vbolshutkin ,

The number-only style was considered to be deprecated since 3.1.0 or so and was finally removed in 3.4.1. I am sorry for the inconvenience, but according to the issue report, that style had some issue with OGNL, so we won't bring it back.

By the way, as it was a backward incompatible change, we mentioned it in the release note including the workaround.

Comment From: jujunchen

Hello, mybatis version is 3.4.6,but i can use arg0 in my project. JDK version 8.0

Hi @vbolshutkin ,

The number-only style was considered to be deprecated since 3.1.0 or so and was finally removed in 3.4.1. I am sorry for the inconvenience, but according to the issue report, that style had some issue with OGNL, so we won't bring it back.

By the way, as it was a backward incompatible change, we mentioned it in the release note including the workaround.

Comment From: harawata

@jujunchen , The deprecated syntax was 0. arg0 works if you don't use @Param nor -parameters compiler option (you should use either one of these, though).