MyBatis异常java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for

1.表现:

    异常表现,数据插入操作执行失败,无语法错误,配置文件检查正常,作为一个低级异常,它很强大

2.异常详细信息:

[ERROR][2014-03-26 16:02:52.490]nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.jd.etms.waybill.dao.OrderRelationDao.insert22
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.jd.etms.waybill.dao.OrderRelationDao.insert22[com.jd.dbs.execution.DefaultConcurrentRequestProcessor:innerExecuteWith]

java.lang.RuntimeException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.jd.etms.waybill.dao.OrderRelationDao.insert22
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.jd.etms.waybill.dao.OrderRelationDao.insert22
	at com.jd.dbs.execution.DefaultConcurrentRequestProcessor.innerExecuteWith(DefaultConcurrentRequestProcessor.java:219)
	at com.jd.dbs.execution.DefaultConcurrentRequestProcessor.executeWith(DefaultConcurrentRequestProcessor.java:162)
	at com.jd.dbs.DBSqlSessionTemplate.executeDefaultConcurrency(DBSqlSessionTemplate.java:567)
	at com.jd.dbs.DBSqlSessionTemplate.insert(DBSqlSessionTemplate.java:255)
	at com.jd.etms.waybill.dao.OrderRelationDao.insert(OrderRelationDao.java:25)
	at com.jd.etms.waybill.dao.OrderRelationDaoTestTest.testInsert(OrderRelationDaoTestTest.java:55)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
	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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.jd.etms.waybill.dao.OrderRelationDao.insert22
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.jd.etms.waybill.dao.OrderRelationDao.insert22
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
	at $Proxy25.insert(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:232)
	at com.jd.dbs.execution.DefaultConcurrentRequestProcessor.innerExecuteWith(DefaultConcurrentRequestProcessor.java:181)
	... 38 more
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.jd.etms.waybill.dao.OrderRelationDao.insert22
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.jd.etms.waybill.dao.OrderRelationDao.insert22
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:124)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:111)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:350)
	... 41 more
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.jd.etms.waybill.dao.OrderRelationDao.insert22
	at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:595)
	at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:437)
	at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:430)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:121)
	... 47 more

3. 解决:

    很多问题会抛出该异常,但本次异常是由于程序执行插入时sqlID填写错误导致,比较隐蔽,程序如下:

 public void insert(OrderRelation orderRelation) {
        if (orderRelation == null) {
            logger.error("insert error,parameter is null");
            throw new IllegalArgumentException("插入订单主增关系异常, parameter is null.");
        } this.getSqlSession().insert(this.getSqlId("queryByOrderId"), orderRelation);
    }

this.getSqlId("queryByOrderId")

本该填写insert语句的SQL ID,因为填写成了query的ID导致这个错误。

你可能感兴趣的:(ORM)