mybatis-3: Space in typeAlias results in the IllegalArgumentException: "Result Maps collection already contains value for"

If you have a trailing space in the alias attribute of a typeAlias definition, like this:

<typeAliases>
  <typeAlias alias="User "  type="com.example.domain.User" />
</typeAliases>

at runtime you get an exception like this:

java.lang.IllegalArgumentException: Result Maps collection already contains value for com.example.persistence.UserMapper.mapper_resultMap[xxx]_association[xxx]

where the map and association referenced in the exception are ones defined in your mapper.

Removing the trailing space fixes the problem, but it took a long time to track down.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I had the same problem while I run my project over JRebel. When I run without it I didn’t have such problem.

It was in SqlSessionFactoryBean

 - <property name="mapperLocations" value="classpath*:sql-mybatis/*.xml" />
 + <property name="mapperLocations" value="classpath:/sql-mybatis/*.xml" />

This happens to me myself yesterday! 😃

I have opened an issue in Spring to see if there is something we can do in the Scanner to avoid this problem.