Result Maps collection already contains value for com.feng.crud.dao.EmployeeMapper.mapper_resultMap[

1、错误的一些信息:

Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\eclipse\eclipse_new_new\maven\ssm-crud3\target\classes\mapper\EmployeeMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\eclipse\eclipse_new_new\maven\ssm-crud3\target\classes\mapper\EmployeeMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.feng.crud.dao.EmployeeMapper.mapper_resultMap[WithDeptResultMap]_association[department]
	at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:613)
	at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:491)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
	... 41 more
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\eclipse\eclipse_new_new\maven\ssm-crud3\target\classes\mapper\EmployeeMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.feng.crud.dao.EmployeeMapper.mapper_resultMap[WithDeptResultMap]_association[department]
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:122)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:94)
	at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:611)
	... 44 more
Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.feng.crud.dao.EmployeeMapper.mapper_resultMap[WithDeptResultMap]_association[department]
	at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:947)

2、原因:

根据以上报错信息错误原因是:
在这个文件中EmployeeMapper.xml
里面有很多相同的id值为WithDeptResult的相同的语句

下面的是个列子,反正就是类似的。

 <resultMap type="com.feng.crud.bean.Employee" id="WithDeptResultMap">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="gender" jdbcType="CHAR" property="gender" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="d_id" jdbcType="INTEGER" property="dId" />
    <association property="department" javaType="com.feng.crud.bean.Department">
    	<id column="id" property="id"/>
    	<result column="name" property="name"/>
    </association>
  </resultMap>
  
   <resultMap type="com.feng.crud.bean.Employee" id="WithDeptResultMap">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="gender" jdbcType="CHAR" property="gender" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="d_id" jdbcType="INTEGER" property="dId" />
    <association property="department" javaType="com.feng.crud.bean.Department">
    	<id column="id" property="id"/>
    	<result column="name" property="name"/>
    </association>
  </resultMap>

3、解决办法,根据报错信息,把对应的id值复制好,到对应的EmployeeMapper.xml文件中Ctrl+F 查找刚刚复制的id的值然后把那个语句块删除掉,或者注释掉

4、产生那个错误的原因之一:
我这个是ssm(springmvc+spring+mybatis)框架的简单crud(增删改查),我使用的是mybatis的逆向工程(mybatis generator),在工程的mbg.xml文件写好之后并且写好了那个对应的测试文件,我重复执行了几次这个文件的测试文件,就导致产生了多个相同的id值的相同语句在相同的*Mapper.xml文件中(测试执行下一次之前没有删除之前的)。

5、发现这个错误参考了这个博主

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值