有没有解决方案通过hibernate在分区后的PostgreSQL表中批量插入?目前我遇到这样的错误…
ERROR org.hibernate.jdbc.AbstractBatcher - Exception executing batch: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61) at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46) at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)....
我已经找到此链接http://lists.jboss.org/pipermail/hibernate- dev/2007-October/002771.html,但我在网上找不到任何地方可以解决此问题或如何解决该问题
您可能想通过设置hibernate.jdbc.factory_class属性尝试使用自定义批处理程序。确保hibernate状态不会检查批处理操作的更新次数可能会解决您的问题,可以通过使自定义批处理程序扩展类BatchingBatcher,然后覆盖方法doExecuteBatch(…)来实现此目的:
@Override protected void doExecuteBatch(PreparedStatement ps) throws SQLException, HibernateException { if ( batchSize == 0 ) { log.debug( "no batched statements to execute" ); } else { if ( log.isDebugEnabled() ) { log.debug( "Executing batch size: " + batchSize ); } try { // checkRowCounts( ps.executeBatch(), ps ); ps.executeBatch(); } catch (RuntimeException re) { log.error( "Exception executing batch: ", re ); throw re; } finally { batchSize = 0; } } }
请注意,新方法不会检查执行准备好的语句的结果。请记住,进行此更改可能会以某种意外的方式(或可能不会)影响hibernate状态。