Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for wrong batch statement ordering with many2many relations #3113

Merged

Conversation

jonasPoehler
Copy link
Contributor

Hello Rob,

this PR fixes an issue, when a List representing a ManyToMany-relation is cleared and then filled with (some of) the original elements. Functionally this resulted in the delete and the following insert statements to be executed within the same batch queue, because with m2m intersection tables the same queue was used for both types of SqlUpdate. The end result was that in these cases the first insert statements were executed before all delete statements were flushed, resulting in a DuplicateKeyException. Additionally, I introduced constants for the delete and insert queue positions for better readability.

@@ -267,8 +270,8 @@ public void clear() {
private void flushBuffer(boolean reset) throws BatchedSqlException {
flushQueue(queues[0]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were unable to find a use of the queue at position 0. Maybe this one is unused?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok ... hmm, I need to look at that.

@rbygrave rbygrave self-requested a review June 16, 2023 23:26
@rbygrave rbygrave added the bug label Jun 16, 2023
@rbygrave rbygrave added this to the 13.19.1 milestone Jun 16, 2023
Copy link
Member

@rbygrave rbygrave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!

@@ -267,8 +270,8 @@ public void clear() {
private void flushBuffer(boolean reset) throws BatchedSqlException {
flushQueue(queues[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok ... hmm, I need to look at that.

@@ -294,7 +294,7 @@ private void saveAssocManyIntersection(boolean queue) {
// build a intersection row for 'delete'
IntersectionRow intRow = many.buildManyToManyMapBean(parentBean, otherDelete, publish);
SpiSqlUpdate sqlDelete = intRow.createDelete(server, DeleteMode.HARD);
persister.executeOrQueue(sqlDelete, transaction, queue);
persister.executeOrQueue(sqlDelete, transaction, queue, BatchControl.DELETE_QUEUE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the bug fix here.

@rbygrave rbygrave merged commit ac1b307 into ebean-orm:master Jun 16, 2023
1 check passed
rbygrave added a commit that referenced this pull request Jun 16, 2023
Followup to #3113, remove unused first BatchControl queue
@rPraml rPraml deleted the bugfix/batch_ordering_many2many_intersection branch August 10, 2023 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants