Postgresql JDBC驱动程序中的批处理更新在自动提交中回滚 [英] Batch update in Postgresql JDBC driver rolls back in autocommit

查看:513
本文介绍了Postgresql JDBC驱动程序中的批处理更新在自动提交中回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Postgres 9.3-1100-jdbc41 JDBC4驱动程序进行批量插入.

I am doing batch inserts using postgres 9.3-1100-jdbc41 JDBC4 driver.

根据JDBC规范,其向上 到应用程序以禁用自动提交并提交或 回滚交易.

According to the JDBC specification, its up to the application to disable autocommit and to commit or rollback the transaction.

就我而言,我没有使用任何事务(即,自动提交为true),但是如果批处理中的某个插入失败,则仍会回滚插入.

In my case, I am not using any transaction(i.e., auto commit is true) but still the inserts are rolled back if one of the insert in the batch fails.

根据JDBC规范如果批处理更新中的命令之一无法正确执行,则此方法将引发 BatchUpdateException,并且JDBC驱动程序可能会或可能不会继续处理其余命令 ."这里并不是说先前执行的命令将被回滚.

According to JDBC specification "If one of the commands in a batch update fails to execute properly, this method throws a BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch.". Here it does not says that previously executed commands will be rolled back.

我的理解错误吗?如果不是,为什么驱动程序会以这种方式运行,如果是,则根据规范,正确的行为是什么.

Is my understanding wrong? If not why driver is behaving in this way and if yes what is the right behavior according to specification.

推荐答案

据我所知,规范本质上是由驱动程序决定的.如果批处理失败,它不会指定是否提交已经处理的工作.

As far as I can tell the spec essentially leaves this up to the driver; it doesn't specify whether or not already-processed work is committed if the batch fails.

PgJDBC在事务中执行批处理,因此,如果批处理的任何部分失败,则将全部中止.

PgJDBC executes the batch in a transaction, so if any part of the batch fails then it will all be aborted.

如果您认为此行为不正确,那么您要做的第一件事就是编写一个测试用例,以证明其他驱动程序始终对PgJDBC表现出不同的方式,并将其提交给

If you feel this behaviour to be incorrect, the first thing you need to do is write a test case demonstrating that other drivers consistently behave a different way to PgJDBC and submit it to the PgJDBC issue tracker. We do not have time to research behaviour of other drivers, so you need to write the test case and run it some other popular databases (MS SQL Server, Oracle, DB2, MySQL, etc) or arrange to have it run by others. If you show that PgJDBC's behaviour differs from how other drivers handle batches then it'll be worth thinking about adding an option to change the behaviour (and working on making it the default eventually).

这篇关于Postgresql JDBC驱动程序中的批处理更新在自动提交中回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆