问题描述
org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [insert into ORC_T_BUSINESS_TRACK (BUSI_NUM, BUSI_TYPE, CREATE_DATE, CREATE_USER_NAME, CREATE_USER_NUM, REMARK, ID) values (?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch updateat org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:643)at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:104)at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:516)at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:394)at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)at com.bsteel.shdc.service.OrcTBusinessTrackServiceImpl$$EnhancerByCGLIB$$416c9ca9.saveOrcTBusinessTrack(<generated>)at com.bsteel.shdc.bankservice.finance.redeem.controller.AuditController.signaTure1(AuditController.java:642)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)at java.lang.reflect.Method.invoke(Unknown Source)at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)at com.bsteel.shdc.manager.permission.filter.AuthFilter.doFilter(AuthFilter.java:101)at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)at org.mortbay.jetty.Server.handle(Server.java:326)at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch updateat org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:262)at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:178)at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)... 47 moreCaused by: java.sql.BatchUpdateException: ORA-01401: inserted value too large for columnat oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:345)at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10844)at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)... 56 more[color=red][/color] 问题补充:以上是报错信息 Map<String,String> user=new HashMap<String,String>(); user.put(LSConstants.USER_LOGIN_NO, (String) getUseInfo().get(LSConstants.USER_LOGIN_NO));user.put(LSConstants.USER_LOGIN_NAME, (String) getUseInfo().get(LSConstants.USER_LOGIN_NAME));orcTBusinessTrackService.saveOrcTBusinessTrack(redeemCode, "ARGUEREDEEM_COUNT", "赎单已完成", user);这是我调用的方法
解决方案
1.插入的数据中,有的字段为null,但是数据库表限制该字段不能为null Could not execute JDBC batch update; SQL [insert into ORC_T_BUSINESS_TRACK (BUSI_NUM, BUSI_TYPE, CREATE_DATE, CREATE_USER_NAME, CREATE_USER_NUM, REMARK, ID) values (?, ?, ?, ?, ?, ?, ?)]; constraint [null];2.批量更新数据时,有些数据的字段值超过了数据库表定义的字段最大值,要么扩大该字段的值,要么对插入的数据进行校验Caused by: java.sql.BatchUpdateException: ORA-01401: inserted value too large for column
解决方案二:
其实吧,出现异常,定位的话只要看Caused by后面的就行了。。Caused by: java.sql.BatchUpdateException: ORA-01401: inserted value too large for column 有个字段的值太大了。。就这么简单。。目测是某个字符串长度没给够,自己检查下数据库表和hibernate配置文件吧
解决方案三:
Could not execute JDBC batch update; SQL [insert into ORC_T_BUSINESS_TRACK (BUSI_NUM, BUSI_TYPE, CREATE_DATE, CREATE_USER_NAME, CREATE_USER_NUM, REMARK, ID) values (?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException没有代码 只能从你上面报出的异常来 推测 1.可能你数据库里面的字段设置不能为空 但是你往做句库做动作的时候 这个字段上的值是空的2.可能是配置文件设置了关联,数据却没有关联造成的,只要数据正确就没有问题。另外,造成这个原因的还可能是数据库的驱动jar包不支持。3.因为Hibernate Tools(或者Eclipse本身的Database Explorer)生成*.hbn.xml工具中包含有catalog="***"(*表示数据库名称)这样的属性,将该属性删除就可以了4.估计是你的列名里面有关键字的原因吧,命名列的时候不要单独使用date,ID...这种关键字