PersistenceException when calling executeBatch() on SqlUpdate #2110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello Rob,
we have discovered a problem in a routine in our application that fills two batched updates in one for-loop and after that calls
executeBatch()
on them. This seems to work perfectely in almost all cases, except, when the number of batched updates equals the maxBatchSize (ornumber % maxBatchSize == 0
). In that case we receive the following exception (reproducable withtestTwoParallelBatches
):When we were trying to fix this, our first intention was, not to throw this exception and instead just return and do nothing (the updates were already flushed). But that brought up the question why the stmtMap in
BatchedPstmtHolder
is cleared in the first place. At every flush the map ofBatchedPstmt
is cleared, resulting in a new object ofBatchedPstmt
being created on the next call toaddBatch()
. Since this results in a wrong array of change-length returned fromexecuteBatch()
(see the second test:testBatchReturnArrayLength
), this didn't look correct either.A possible fix would maybe be not to clear the map, but rather clear the list of "elements-still-to-flush" for every
BatchedPstmt
and not recreate the statement after each flush. But since I am not all that sure about the overall architecture thoughts on this matter, I decided, to just provide these two tests and maybe start a discussion.I hope that I made the problem clear enough for you to understand, the code might explain it even better.
Looking forward to your thoughts on this!
All the best
Jonas