gpt4 book ai didi

带有分区postgresql的hibernate插入批处理

转载 作者:行者123 更新时间:2023-11-29 11:14:06 25 4
gpt4 key购买 nike

是否有通过 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 属性来尝试使用自定义 Batcher。确保 hibernate 不会检查批处理操作的更新计数可能会解决您的问题,您可以通过使自定义 Batcher 扩展 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 。

关于带有分区postgresql的hibernate插入批处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/83093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com