Junit测试错误:### Error building SqlSession

错误代码:

org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com/jkw100/mybatis/mapper/PatientMapper.xml
### The error occurred while processing mapper_resultMap[BaseResultMap]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.jkw100.mybatis.mapper.PatientMapper.BaseResultMap
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:82)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:66)
at com.jkw100.mybatis.mapper.PatientMapperTest.setUp(PatientMapperTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.jkw100.mybatis.mapper.PatientMapper.BaseResultMap
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:115)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:95)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
... 25 more
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.jkw100.mybatis.mapper.PatientMapper.BaseResultMap
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.loadXmlResource(MapperAnnotationBuilder.java:167)
at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:118)
at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:72)
at org.apache.ibatis.binding.MapperRegistry.addMappers(MapperRegistry.java:97)
at org.apache.ibatis.binding.MapperRegistry.addMappers(MapperRegistry.java:105)
at org.apache.ibatis.session.Configuration.addMappers(Configuration.java:667)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:331)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:113)
... 27 more
Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.jkw100.mybatis.mapper.PatientMapper.BaseResultMap
at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:802)
at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:774)
at org.apache.ibatis.session.Configuration.addResultMap(Configuration.java:556)
at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java:217)
at org.apache.ibatis.builder.ResultMapResolver.resolve(ResultMapResolver.java:47)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:285)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:252)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:244)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:116)
... 36 more

Result Maps collection already contains value for com.jkw100.mybatis.mapper.PatientMapper.BaseResultMap 看到这句是因为mapper.xml文件中id为BaseResultMap这个名称重复 删除重复解决问题

在用mybatis逆向工程自动生成mapper.xml的时候 如果不小心多运行了一次 那么在mapper.xml文件中的代码会多出一份 这样就会造成相同的id有两个或多个了 而相同的文件是不会多生成的

时间: 2024-10-13 00:05:00

Junit测试错误:### Error building SqlSession的相关文章

### Error building SqlSession.

1.错误描述 Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; li

测试错误ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.问题的解决

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. 错误:状态记录器没有找到log4j2配置文件,将使用默认配置:只将错误记录到控制台. 原因:log4j2的jar包是hibernate5框架自带的log4j2,在ssh中即使自己导入了第三方日志包,系统依然会调用log4j2,缺省默认配置文件 log4j2.x

spring3 + mybatis + maven:junit测试错误

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [G:\workspaces\workspace_gmq\springmvc.demo\target\classes\com\gmq\service\impl\UserServiceImpl.class]; nested exception is java.lang.Illeg

Junit测试代码时出现initializationError 错误

首先代码没有错误,执行Junit测试时出现以上错误.上网查资料发现少了包 从网上下载了一个jar包解决了hamcrest-core-1.3.jar 现在下载包搜索的好多坑,有的网站必须注册才能下载,而且下载的有的还是 很垃圾.所以给大家推荐一个下载网站:http://www.java2s.com  平时找包就so easy了

搭建项目Maven+springMVC+hibernate时,JUnit测试出现报ClassNotFoundException错误的解决

最近在搭建Maven+springMVC+hibernate项目,正常启动项目时一切正常,但JUNIT测试时出现报ClassNotFoundException错误,经过仔细排查发现没有生成class文件. 现在解决如下:

JUnit测试框架的使用

1.学习Junit框架的使用 可通过以下两个示例进行学习. A.Junit使用方法示例1 1)把Junit引入当前项目库中 新建一个 Java 工程—coolJUnit,打开项目coolJUnit 的属性页 -> 选择“Java Build Path”子选项 -> 点选“Add Library…”按钮 -> 在弹出的“Add Library”对话框中选择 JUnit(图1),并在下一页中选择版本 Junit 4 后点击“Finish”按钮.这样便把 JUnit 引入到当前项目库中了. 2

spring集成Mybatis框架,junit测试

1.Spring的xml文件配置如下: 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:aop="http://www

JUnit测试框架的使用经验分享

1.学习Junit框架的使用可通过以下两个示例进行学习.A.Junit使用方法示例11)把Junit引入当前项目库中新建一个 Java 工程—coolJUnit,打开项目coolJUnit 的属性页 -> 选择“Java Build Path”子选项 -> 点选“Add Library…”按钮 -> 在弹出的“Add Library”对话框中选择 JUnit,并在下一页中选择版本 Junit 4 后点击“Finish”按钮.这样便把 JUnit 引入到当前项目库中了.2)新建单元测试代码

android junit 测试 简要步骤

android junit 测试 1.新建一个类继承TestCase这个类 2.AndroidManifest.xml, 加入<uses-library android:name="android.test.runner" /> <!-- 记住这个一要放在application外面,不然会出现配置错误 信息 -->      <instrumentation android:name="android.test.InstrumentationTe