zoukankan      html  css  js  c++  java
  • mybatisGenerator 代码自动生成报错 Result Maps collection already contains value for BaseResultMap【转】

    由于mybatis简单易学,比起Hibername来,更容易上手,代码也能自动生成。这几天研究了下代码自动生成的,参考:

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

    但是把代码复制进来,运行了下,却跑不起来,报以下错误:

    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

    后来在CSDN上下载了个可以直接运行的eclipse 项目,再与之前的项目对比,好像也没什么不同。最后使绝招:代码对比工具,发现生成的PetMapper.xml多了几百行!!!

    因为我在使用generator自动生成工具之后,又修改了generator,本以为修改命令里面的-overwrite参数能自动覆盖,但是事实上不可以,所以之前的和现在的两个混合在一起导致了错误。解决办法就是删掉之前生成的mapper和pojo包,重新生成,然后复制到工程下面。问题就解决了!!

    原来是我在运行时没有把之前已经生成的PetMapper.xml删除掉,再次生成代码时,又附加了上去!所以在运行代码生成之前,要把以前已经生成的xml文件清掉,以妨出错。

    不畏浮云遮望眼,只缘身在此山中,安静提高自己,功过留给别人去说。
  • 相关阅读:
    C#中使用事务
    C#中执行数据库存储过程
    构建ASP.net的AJAX开发环境
    C#开发数据库技巧汇总
    索引的作用及其使用
    C#中的多态性
    C#中调用C++的DLL
    不借助其它变量交换两变量值
    ASP.NET页面间传值的9种方式
    TERSUS无代码开发(笔记11)TERSUS框架学习框架基本信息修改
  • 原文地址:https://www.cnblogs.com/vivizhang/p/6016476.html
Copyright © 2011-2022 走看看