Mybatisgenerator code automatically generates an error result Maps collection already contains value for Baseresultmap

Source: Internet
Author: User

Since MyBatis is easy to learn, it is easier to get started than Hibername, and the code can be generated automatically. These days the following code is automatically generated, for reference:

http://0609xiaohua.iteye.com/blog/1453570

But copy the code in, run the next, but can't run up, reported the following error:

Exception in thread "main" Java.lang.ExceptionInInitializerError
At Com.test.Test.main (test.java:12)
Caused by:org.apache.ibatis.exceptions.PersistenceException:
# # # Error Building sqlsession.
# # # The error may exist in Com/mapper/petmapper.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.mapper.PetMapper.BaseResultMap
At Org.apache.ibatis.exceptions.ExceptionFactory.wrapException (Exceptionfactory.java:8)
At Org.apache.ibatis.session.SqlSessionFactoryBuilder.build (sqlsessionfactorybuilder.java:32)
At Org.apache.ibatis.session.SqlSessionFactoryBuilder.build (sqlsessionfactorybuilder.java:16)
At Com.util.sessionfactory.<clinit> (sessionfactory.java:21)
... 1 more
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.mapper.PetMapper.BaseResultMap
At Org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration (xmlconfigbuilder.java:85)
At Org.apache.ibatis.builder.xml.XMLConfigBuilder.parse (xmlconfigbuilder.java:69)
At Org.apache.ibatis.session.SqlSessionFactoryBuilder.build (sqlsessionfactorybuilder.java:30)
... 3 more
caused By:java.lang.RuntimeException:Error parsing Mapper XML. Cause:java.lang.IllegalArgumentException:Result Maps Collection already contains value for Com.mapper.PetMapper.BaseResultMap
At Org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement (xmlmapperbuilder.java:97)
At Org.apache.ibatis.builder.xml.XMLMapperBuilder.parse (xmlmapperbuilder.java:73)
At Org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement (xmlconfigbuilder.java:255)
At Org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration (xmlconfigbuilder.java:83)
... 5 more
caused By:java.lang.IllegalArgumentException:Result Maps collection already contains value for Com.mapper.PetMapper.BaseResultMap
At Org.apache.ibatis.session.configuration$strictmap.put (configuration.java:578)
At Org.apache.ibatis.session.configuration$strictmap.put (configuration.java:551)
At Org.apache.ibatis.session.Configuration.addResultMap (configuration.java:356)
At Org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap (mapperbuilderassistant.java:138)
At Org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement (xmlmapperbuilder.java:231)
At Org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement (xmlmapperbuilder.java:201)
At Org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements (xmlmapperbuilder.java:196)
At Org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement (xmlmapperbuilder.java:93)
... 8 more

Later, I downloaded an Eclipse project that could run directly on the CSDN, and compared it to the previous project, as if it were no different. Finally make a trick: code comparison tool, found that the generated petmapper.xml more than hundreds of lines!!!

It turns out that I did not delete the previously generated petmapper.xml when I was running, and then added it again when I generated the code again! So before you run code generation, you need to clear out the XML files that were previously generated to make a mistake.

Mybatisgenerator code automatically generates an error result Maps collection already contains value for Baseresultmap

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.