tro*_*sta 12 postgresql hibernate insert database-partitioning
是否有分区postgresql表中通过hibernate批量插入的解决方案?目前我收到这样的错误......
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)....
Run Code Online (Sandbox Code Playgroud)
我发现这个链接http://lists.jboss.org/pipermail/hibernate-dev/2007-October/002771.html但我不能随时随地在网络上找到的这个问题很好解决,或者它如何能得到解决
小智 4
您可能想通过设置 hibernate.jdbc.factory_class 属性来尝试使用自定义批处理程序。确保 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,新方法不会检查执行准备语句的结果。请记住,进行此更改可能会以某种意想不到的方式影响休眠(也可能不会)。
| 归档时间: |
|
| 查看次数: |
8416 次 |
| 最近记录: |