i was using simple @Arg(column, type). Tried to add name=... to some args that had the same type, to make things more resilient. this broke the mapper.

  1. having name's on just some args of a resultMap doesn't seem supported (would be nice)
  2. since it isn't, can an additional check be added for such situations that throws something better worded about this not being supported?
  3. a broken mapper may actually be created if another constructor matches the args with name. see test case below, that should throw a different exception right now

MyBatis version

4.5.13, current master

Test case or example project

public class PartialArgsTest {

  record Post(String section, Timestamp createdOn, String subject) {
    public Post(String section, Timestamp subject) {
      this(null, null, null); // absurd, but doesn't matter anyway
    }
  }

  interface Mapper {
    @Select("SELECT * FROM post")
    @Arg(column = "SECTION", name = "section", javaType = String.class)
    @Arg(column = "CREATED_ON", javaType = Timestamp.class)
    @Arg(column = "SUBJECT", name = "subject", javaType = String.class)
    List<Post> getPosts();
  }

  @Test()
  void shouldGetDataOrFailOnMapperCreation() throws Exception {
    final Environment environment = new Environment("test", new JdbcTransactionFactory(),
      BaseDataTest.createBlogDataSource());
    final Configuration config = new Configuration(environment);

    assertThrows(BuilderException.class, () -> {
      config.addMapper(Mapper.class); // this should throw, if all or no @Arg's must have names

      // this continuation should not throw if partial names are ok (but actually throws right now):
      var sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
      try (SqlSession session = sqlSessionFactory.openSession()) {
        Mapper mapper = session.getMapper(Mapper.class);
        var result = mapper.getPosts();
      }
    });
  }
}

Comment From: wickedtornado

record Post(String section, Timestamp createdOn, String subject) { public Post(String section, Timestamp subject) { this(null, null, null); } } Something is wrong here, seems to be a incorrect constructor

Comment From: dirk-tf

Something is wrong here

This minimalist example is absurd, yes, since it is stripped down to only the parts necessary to highlight the bug.

Comment From: dirk-tf

Doesn't look like there is any interest, so i'll just close this issue

Comment From: harawata

Hello @dirk-tf ,

I'm sorry for a belated reply. This will be addressed in 3.6.0 i.e. MyBatis throws exception when there are @Args with and without name.

name is useless if @Arg matches the order of the target constructor (i.e. it does not make anything more resilient). See the original request #721 .