一、异常描述
关于mybatis的xml脚本执行过程报" SQLErrorCodesFactory: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]...org.springframework.jdbc.BadSqlGrammarException: ... bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00918: 未明确定义列"异常,详情日志如下>>
[18:12:47.248] [INFO] [<T=R0MMpXEBz00dk8XP>] XmlBeanDefinitionReader: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]@b@[18:12:47.268] [INFO] [<T=R0MMpXEBz00dk8XP>] SQLErrorCodesFactory: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]@b@[18:12:47.270] [INFO] [<T=R0MMpXEBz00dk8XP>] ReportMPController: 新增失败@b@org.springframework.jdbc.BadSqlGrammarException: @b@### Error updating database. Cause: java.sql.SQLSyntaxErrorException: ORA-00918: 未明确定义列@b@@b@### The error may involve com.xwood.pms.dao.ReportMPConfDAO.batchInsert-Inline@b@### The error occurred while setting parameters@b@### SQL: INSERT INTO REPORT_MAS_INFO (ID, MAS_ID,MAS_TYPE,MAS_NAME,GPT_ID,BA_TYPE,DPT_ID,STATUS,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE)select REP_MAS_SEQ.NEXTVAL,?,?,?,?,?,?,'Y','sys',systimestamp,'sys',systimestamp,?,? from dual union all select REP_MAS_SEQ.NEXTVAL,?,?,?,?,?,?,'Y','sys',systimestamp,'sys',systimestamp,?,? from dual union all select REP_MAS_SEQ.NEXTVAL,?,?,?,?,?,?,'Y','sys',systimestamp,'sys',systimestamp,?,? from dual @b@### Cause: java.sql.SQLSyntaxErrorException: ORA-00918: 未明确定义列@b@@b@; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00918: 未明确定义列@b@@b@ at org.@b@ EASE.jar:3.2.13.RELEASE]@b@ at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:91) [spring-aop-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at com.xwood.pms.aop.LogAppendAdvice.logController(LogAppendAdvice.java:47) [bin/:?]@b@ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]@b@ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_11]@b@ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]@b@ at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]@b@ at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) [spring-aop-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) [spring-aop-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65) [spring-aop-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91) [spring-aop-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633) [spring-aop-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at com.xwood.pms.web.controller.ReportMPController$$EnhancerBySpringCGLIB$$32f479aa.addEvent(<generated>) [spring-core-3.2.13.RELEASE-3.2.13.RELEASE.jar:?]@b@ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]@b@ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_11]@b@ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]@b@ at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]@b@ at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) [spring-web-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) [spring-web-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) [spring-webmvc-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743) [spring-webmvc-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672) [spring-webmvc-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82) [spring-webmvc-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at com.xwood.soofa.web.DefWebRequestHandler.handleRequest(DefWebRequestHandler.java:61) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.filter.DefaultFilterChain.doFinal(DefaultFilterChain.java:64) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.filter.DefaultFilterChain.doFilter(DefaultFilterChain.java:57) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.pms.common.filter.XssSecurityFilter.doFilter(XssSecurityFilter.java:50) [bin/:?]@b@ at com.xwood.soofa.web.filter.DefaultFilterChain.doFilter(DefaultFilterChain.java:52) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.filter.impl.PostJsonToFormFilter.doFilter(PostJsonToFormFilter.java:38) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.filter.DefaultFilterChain.doFilter(DefaultFilterChain.java:52) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.filter.impl.FileUploadFilter.doFilter(FileUploadFilter.java:40) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.filter.DefaultFilterChain.doFilter(DefaultFilterChain.java:52) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.DefWebDispatcher.handleRequest(DefWebDispatcher.java:134) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.sar.SARContextBean.handleWebRequest(SARContextBean.java:170) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.soofa-baseWebRequestHandler.handleRequest(soofa-baseWebRequestHandler.java:44) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.filter.DefaultFilterChain.doFinal(DefaultFilterChain.java:64) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.filter.DefaultFilterChain.doFilter(DefaultFilterChain.java:57) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.filter.impl.CommonWebFilter.doFilter(CommonWebFilter.java:46) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.filter.DefaultFilterChain.doFilter(DefaultFilterChain.java:52) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.web.Defsoofa-baseWebDispatcher.dispatch(Defsoofa-baseWebDispatcher.java:80) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.soofa-baseContextBean.handleWebRequest(soofa-baseContextBean.java:182) [soofa-base-5.2.6.jar:5.2.6]@b@ at com.xwood.soofa.protocol.web.soofa-baseServlet.service(soofa-baseServlet.java:63) [soofa-base-5.2.6.jar:5.2.6]@b@ at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684) [jetty-servlet-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1496) [jetty-servlet-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at com.xwood.soofa.protocol.jetty.JettyResourceFilter.doFilter(JettyResourceFilter.java:73) [soofa-base-5.2.6.jar:5.2.6]@b@ at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1467) [jetty-servlet-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501) [jetty-servlet-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:229) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429) [jetty-servlet-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.Server.handle(Server.java:370) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865) [jetty-http-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240) [jetty-http-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) [jetty-server-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696) [jetty-io-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53) [jetty-io-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) [jetty-util-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) [jetty-util-8.1.16.v20140903-8.1.16.jar:8.1.16.v20140903]@b@ at java.lang.Thread.run(Thread.java:745) [?:1.8.0_11]@b@Caused by: java.sql.SQLSyntaxErrorException: ORA-00918: 未明确定义列@b@@b@ at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1044) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1329) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3685) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1376) ~[ojdbc6-11.2.0.3.0-11.2.0.3.0.jar:11.2.0.3.0]@b@ at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493) ~[druid-1.0.12-1.0.12.jar:1.0.12]@b@ at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:45) ~[mybatis-3.3.0-3.3.0.jar:3.3.0]@b@ at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:73) ~[mybatis-3.3.0-3.3.0.jar:3.3.0]@b@ at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49) ~[mybatis-3.3.0-3.3.0.jar:3.3.0]@b@ at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:115) ~[mybatis-3.3.0-3.3.0.jar:3.3.0]@b@ at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75) ~[mybatis-3.3.0-3.3.0.jar:3.3.0]@b@ at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:170) ~[mybatis-3.3.0-3.3.0.jar:3.3.0]@b@ at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:157) ~[mybatis-3.3.0-3.3.0.jar:3.3.0]@b@ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]@b@ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_11]@b@ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_11]@b@ at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_11]@b@ at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386) ~[mybatis-spring-1.2.3-1.2.3.jar:1.2.3]@b@ ... 78 more
xml配置如下
<?xml version="1.0" encoding="UTF-8" ?> @b@<!DOCTYPE mapper @b@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @b@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">@b@<mapper namespace="com.xwood.pms.dao.ReportMPCDAO"> @b@ @b@ <!-- 批量新增 -->@b@ <insert id="batchInsert" parameterType="com.xwood.pms.dao.ReportMPCDTO">@b@ INSERT INTO REPORT_MAS_INFO@b@ (ID,@b@ MAS_ID,@b@ MAS_TYPE,@b@ MAS_NAME, @b@ STATUS,@b@ CREATED_BY,@b@ CREATED_DATE,@b@ UPDATED_BY,@b@ UPDATED_DATE)@b@ SELECT REP_MAS_SEQ.nextval id,@b@ c.* FROM (@b@ <foreach collection="datas" separator="union all"@b@ item="rmi" index="index" >@b@ select@b@ #{rmi.masId,jdbcType=VARCHAR} masId,@b@ #{rmi.masType,jdbcType=VARCHAR} masType,@b@ #{rmi.masName,jdbcType=VARCHAR} masName, @b@ 'Y' status,@b@ 'sys' createdBy,@b@ systimestamp createdDate,@b@ 'sys' updatedBy,@b@ systimestamp updatedDate@b@ from dual@b@ </foreach>@b@ ) c@b@ </insert>@b@ @b@ @b@ @b@</mapper>
二、解决方法
修改配置如下
<?xml version="1.0" encoding="UTF-8" ?> @b@<!DOCTYPE mapper @b@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @b@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">@b@<mapper namespace="com.xwood.pms.dao.ReportMPCDAO">@b@ @b@ @b@ <!-- 批量新增 -->@b@ <insert id="batchInsert" parameterType="com.xwood.pms.dao.ReportMPCDTO">@b@ INSERT INTO REPORT_MAS_INFO@b@ (ID,@b@ MAS_ID,@b@ MAS_TYPE,@b@ MAS_NAME,@b@ GPT_ID,@b@ BA_TYPE,@b@ DPT_ID,@b@ STATUS,@b@ CREATED_BY,@b@ CREATED_DATE,@b@ UPDATED_BY,@b@ UPDATED_DATE)@b@ SELECT REP_MAS_SEQ.nextval id,@b@ c.masId,c.masType,c.masName,c.gptId,c.baType,c.dptId,c.status,c.createdBy,c.createdDate,c.updatedBy,c.updatedDate FROM (@b@ <foreach collection="datas" separator="union all"@b@ item="rmi" index="index" >@b@ select@b@ #{rmi.masId,jdbcType=VARCHAR} masId,@b@ #{rmi.masType,jdbcType=VARCHAR} masType,@b@ #{rmi.masName,jdbcType=VARCHAR} masName,@b@ #{rmi.gptId,jdbcType=VARCHAR} gptId,@b@ #{rmi.baType,jdbcType=VARCHAR} baType,@b@ #{rmi.dptId,jdbcType=VARCHAR} dptId,@b@ 'Y' status,@b@ 'sys' createdBy,@b@ systimestamp createdDate,@b@ 'sys' updatedBy,@b@ systimestamp updatedDate@b@ from dual@b@ </foreach>@b@ ) c@b@ </insert> @b@ @b@</mapper>