0

I am currently writing a Java application and using Batch Insertion in autocommit mode. My question is if I insert 4 rows in a batch and a BatchUpdateException is thrown because the second row of the batch have trigger a Duplicate Key violation! Does the DBC driver continue to process the 2 remaining row leaving the database with 3 inserted rows? Or does it stop at row 2 leaving the database with 1 inserted rows ? Or it rollback the whole batch leaving the database state with 0 inserted rows?

1
  • Why don't you just try to do it? On a test database, obviously. Normally, a batch would be entirely rolled back (or at least, I'd expect it to be - I've never explicitly worked with that library); however, with autocommit on, I suspect that statements are potentially being executed WITH NC, meaning some of the rows may be updated. Which rows... is dependent on how any 'ordering' is implemented in the driver - if it decides to thread it, results are undefined. Commented Nov 26, 2012 at 16:40

1 Answer 1

2

It works as this:

You have the chunk size mentioned in the step. Say for example the chunk size is 10.

So, every time a batch of 10 items will be committed.

Say, in a batch of 10 item, the 4th item throws duplicate key exception as is your case.

In that case, the whole batch will be rejected and the job will stop (if the skip policy is not implemented).

However, all the previous correct chunks which are already committed, will not be rolled back.

To add further, if after removing the incorrect data, if the same job is restarted, then the job will start exactly from the chunk where it errored last.

So, nothing happens to the data already written.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the tricky part: " if after removing the incorrect data, if the same job is restarted, then the job will start exactly from the chunk where it errored last."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.