I found the following problem and report it. If I have time, I will fix it and create a pull request.

MyBatis version

3.5.11

Database vendor and version

SQLite3 (probably for any vendor)

Test case or example project

https://github.com/tsasaki609/mybatis-3-sscce-foreach-with-bind

Steps to reproduce

check out the example project and run

Expected result

09:44:57.720 [main] DEBUG mybatis.sscce.foreach.with.bind.FooMapper.countBar - ==> Preparing: SELECT count() FROM bar WHERE id IN ( ? , ? ) 09:44:57.755 [main] DEBUG mybatis.sscce.foreach.with.bind.FooMapper.countBar - ==> Parameters: test001(String), test002(String) 09:44:57.787 [main] DEBUG mybatis.sscce.foreach.with.bind.FooMapper.countBar - <== Total: 1 2*

Actual result

09:44:57.720 [main] DEBUG mybatis.sscce.foreach.with.bind.FooMapper.countBar - ==> Preparing: SELECT count() FROM bar WHERE id IN ( ? , ? ) 09:44:57.755 [main] DEBUG mybatis.sscce.foreach.with.bind.FooMapper.countBar - ==> Parameters: test002(String), test002(String) 09:44:57.787 [main] DEBUG mybatis.sscce.foreach.with.bind.FooMapper.countBar - <== Total: 1 1*

Comment From: harawata

Thank you for the report, @tsasaki609 .

This is a duplicate of #575 actually. In your case, defining getText() may be sufficient, but there is no elegant workaround for complex cases, unfortunately.

Comment From: tsasaki609

@harawata Thanks for the reply. Yes, you are right, we just need to define getter in the simple case. Perhaps a more complex case could be solved as well. If so, I don't see the benefit of having bind available inside foreach. Wouldn't it be better if it were not available?

Comment From: harawata

@tsasaki609 ,

Are you proposing to update the DTD? I'm not familiar with DTD, but is it possible to avoid <bind> nested inside other tags like <if>?

<foreach ...>
  <if ...>
    <bind ...>

Comment From: tsasaki609

@harawata , Yes, I think updating the DTD would solve the confusion, but I can't be sure. For example, the following defines that a <bind> can be placed inside a <foreach>.

https://github.com/mybatis/mybatis-3/blob/7cacabcf61c1b1a595ef681d790a97ee91bda14e/src/main/resources/org/apache/ibatis/builder/xml/mybatis-3-mapper.dtd#L272

Comment From: harawata

@tsasaki609 ,

We plan to address the original issue you reported in the next minor update 3.6.x (cf. #2760 )