mybatis generator自动生成代码报The error occurred while processing mapper_resultMap[BaseResultMap]错误的解决方法
今天在用mybatis自动生成代码之后遇到了一个错误:
org.apache.ibatis.exceptions.PersistenceException : ### Error building SqlSession. ### The error may exist in com/erp/webservice/mapper/UsersMapper.xml ### The error occurred while processing mapper_resultMap[BaseResultMap] ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException : Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java: 23 ) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java: 51 ) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java: 35 ) at com.erp.webservice.test.Test.<clinit>( Test.java: 22 ) Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException : Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java: 107 ) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java: 89 ) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java: 49 ) ... 2 more Caused by: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException : Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java: 113 ) at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java: 88 ) at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java: 325 ) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java: 105 ) ... 4 more Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java: 710 ) at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java: 682 ) at org.apache.ibatis.session.Configuration.addResultMap(Configuration.java: 473 ) at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java: 204 ) at org.apache.ibatis.builder.ResultMapResolver.resolve(ResultMapResolver.java: 44 ) at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java: 277 ) at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java: 244 ) at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java: 236 ) at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java: 109 ) ... 7 more Exception in thread "main" java.lang.NullPointerException at com.erp.webservice.test.Test.main( Test.java: 29 ) |
后来发现是我运行了多次自动生成代码的程序,导致了com/erp/webservice/mapper/UsersMapper.xml的内容多出来很多,原来自动生成代码的时候生成的XML代码不是覆盖原来的,而是附加的XML的尾部的。
第一次运行自动生成代码程序:
第二次运行自动生成代码程序:
看看,XML文件明显大了很多,只要删掉原来的XML然后重新运行自动生成代码的程序即可。
或者去工作空间吧生成的东西都删除一边重新生成