无法执行JDBC批量更新;未分类SQL的SQLException

时间:2012-09-15 22:50:37

标签: database spring hibernate jdbc

我需要一些帮助,让我告诉你我的上下文,我们有两个测试环境,其中一个是将web应用程序定向到postgres中的一个数据库,app在这里运行得很好,在另一个环境中我们有两个数据库是从属数据库和主数据库,并且在应用程序中显示与数据库相关的错误。

有一个名为讨论的表,另一个名为network_discussion,当我立即保存讨论时我保存到network_discussion,但是在第二个环境中没有工作,我认为这是与GRANT访问有关但显然不是,这是错误跟踪:

2012-09-15 15:10:27,162|TP-Processor12|ERROR|mp_sites|web|mpmvstage|/home/matchpoint-web/yfroot||Hibernate operation: Could not execute JDBC batch update; uncategorized SQLException for SQL [insert into users.network_discussion (network_id, user_discussion_id, title, last_updated_dt, id) values (?, ?, ?, ?, ?)]; SQL state [null]; error code [0]; Batch entry 0 insert into users.network_discussion (network_id, user_discussion_id, title, last_updated_dt, id) values (33214047252677632, 33495522229786655, company-corp.com_newdisa, 2012-09-15 15:10:27.153000 -07:00, 33495522229786656) was aborted.  Call getNextException to see the cause.; nested exception is java.sql.BatchUpdateException: Batch entry 0 insert into users.network_discussion (network_id, user_discussion_id, title, last_updated_dt, id) values (33214047252677632, 33495522229786655, company-corp.com_newdisa, 2012-09-15 15:10:27.153000 -07:00, 33495522229786656) was aborted.  Call getNextException to see the cause.
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: Could not execute JDBC batch update; uncategorized SQLException for SQL [insert into users.network_discussion (network_id, user_discussion_id, title, last_updated_dt, id) values (?, ?, ?, ?, ?)]; SQL state [null]; error code [0]; Batch entry 0 insert into users.network_discussion (network_id, user_discussion_id, title, last_updated_dt, id) values (33214047252677632, 33495522229786655, company-corp.com_newdisa, 2012-09-15 15:10:27.153000 -07:00, 33495522229786656) was aborted.  Call getNextException to see the cause.; nested exception is java.sql.BatchUpdateException: Batch entry 0 insert into users.network_discussion (network_id, user_discussion_id, title, last_updated_dt, id) values (33214047252677632, 33495522229786655, company-corp.com_newdisa, 2012-09-15 15:10:27.153000 -07:00, 33495522229786656) was aborted.  Call getNextException to see the cause.
java.sql.BatchUpdateException: Batch entry 0 insert into users.network_discussion (network_id, user_discussion_id, title, last_updated_dt, id) values (33214047252677632, 33495522229786655, company-corp.com_newdisa, 2012-09-15 15:10:27.153000 -07:00, 33495522229786656) was aborted.  Call getNextException to see the cause.
    at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2512)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1314)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:347)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2574)
    at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:584)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:500)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:473)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:267)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:623)
    at com.netblue.matchpoint.service.DiscussionService$$EnhancerByCGLIB$$b685dad0.addOrGetDiscussions(<generated>)
    at com.netblue.matchpoint.filter.DiscussionFilter.doFilter(DiscussionFilter.java:30)
    at com.netblue.matchpoint.sitecontroller.MpBaseSiteController.getFilteredParams(MpBaseSiteContr

它继续,我的意思是错误跟踪继续更多,所以任何帮助给我一个想法将是伟大的,我已经在谷歌跟踪这个,但没有结果,谢谢。

2 个答案:

答案 0 :(得分:1)

我实际上解决了麻烦,这真的很痛苦,但感谢上帝,我可以。正如我所说的,它在某些环境中使用数据库,但在其他环境不起作用,麻烦的是我有一个多个保存和依赖寄存器,但第一个需要一些时间来保存,所以当我保存第二个寄存器(不同的表,第二个依赖于第一个)密钥的数据尚未保存,因此我无法像通常那样保存级联,因为它需要更改大量代码,因为这这不是一个'从零开始'的开发,所以我所做的就是深入挖掘代码并获取数据的确切保存位置,然后保存其他寄存器。所以基本上如果你跟踪这个奇怪的错误,没有什么比试图保存在DB中的损坏数据更特别。

答案 1 :(得分:1)

BatchUpdateException.getNextException没有帮助时(或者它只返回null)时,也可以disable batching in hibernate:在hibernate会话配置中设置hibernate.jdbc.factory_class=org.hibernate.jdbc.NonBatchingBatcherFactory(当然这应该只能解决问题,不应永远设置。