Result Maps collection already contains value for com.feng.crud.dao.EmployeeMapper.mapper_resultMap[
阿新 • • 發佈:2020-12-28
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、發現這個錯誤參考了這個博主