Mybatis异常-java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.NUMBE

转载请注明来源:http://blog.csdn.net/loongshawn/article/details/50496202

运行环境

SpringBoot

Mybatis异常摘要

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.NUMBER

Mybatis异常详细

2016-01-11-10-45 [pool-2-thread-1] [org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler] [ERROR] - Unexpected error occurred in scheduled task.
  org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.NUMBER
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)
        at com.sun.proxy.$Proxy30.insert(Unknown Source)
        at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:237)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:79)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
        at com.sun.proxy.$Proxy51.insertFailureRequestList(Unknown Source)
        at com.autonavi.service.impl.gaokuai.ExceptionHandleServiceImpl.insertFailureRequestList(ExceptionHandleServiceImpl.java:21)
        at com.autonavi.method.gaokuai.IssueUpload.action1(IssueUpload.java:92)
        at com.autonavi.task.ScheduledTasks.executeUploadTask(ScheduledTasks.java:56)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

异常产生原因

Caused by: org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.NUMBER
        at org.apache.ibatis.builder.BaseBuilder.resolveJdbcType(BaseBuilder.java:67)
        at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.buildParameterMapping(SqlSourceBuilder.java:94)
        at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.handleToken(SqlSourceBuilder.java:73)
        at org.apache.ibatis.parsing.GenericTokenParser.parse(GenericTokenParser.java:47)
        at org.apache.ibatis.builder.SqlSourceBuilder.parse(SqlSourceBuilder.java:54)
        at org.apache.ibatis.builder.xml.dynamic.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:40)
        at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:241)
        at org.apache.ibatis.executor.statement.BaseStatementHandler.(BaseStatementHandler.java:61)
        at org.apache.ibatis.executor.statement.PreparedStatementHandler.(PreparedStatementHandler.java:36)
        at org.apache.ibatis.executor.statement.RoutingStatementHandler.(RoutingStatementHandler.java:42)
        at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:348)
        at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:43)
        at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:108)
        at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:145)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:134)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355)
        ... 22 more
Caused by: java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.NUMBER
        at java.lang.Enum.valueOf(Enum.java:238)
        at org.apache.ibatis.type.JdbcType.valueOf(JdbcType.java:21)
        at org.apache.ibatis.builder.BaseBuilder.resolveJdbcType(BaseBuilder.java:65)
        ... 42 more

异常排查

XML中是这样写的

"failureRequestValue">
        #{ID, jdbcType=NUMBER},
        #{CURRENT_DATE, jdbcType=VARCHAR},
        #{CURRENT_HOUR, jdbcType=NUMBER},
        #{CURRENT_MIN, jdbcType=NUMBER},
        #{ERROR_MESSAGE, jdbcType=VARCHAR}      

但是查阅官方文档,发现Mybatis中jdbcType整形应该为NUMERIC,并没有所谓的oracle中的整形NUMBER,所以这点应该记住。

"failureRequestValue">
        #{id, jdbcType=NUMERIC},
        #{current_date, jdbcType=VARCHAR},
        #{current_hour, jdbcType=NUMERIC},
        #{current_min, jdbcType=NUMERIC},
        #{error_message, jdbcType=VARCHAR}      

上述错误导致的原因在于Mybatis的jdbcType类型没有弄清楚,Mybatis中数值用NUMERIC,而不是oracle中的NUMBER。

有关Mybatis中的jdbcType详细介绍,请查阅MyBatis JdbcType 与Oracle、MySql数据类型对应关系详解

你可能感兴趣的:(SpringBoot,Oracle,MyBatis)