Skip to content

Fix JPA event publication delete batching to bind each batch #1701

Closed

Description

@char-yb

Problem

JpaEventPublicationRepository.deletePublications(List<UUID>) splits identifiers using DELETE_BATCH_SIZE = 100, but the delete query currently binds the original full identifier list for every batch iteration.

That means the code creates batches, but the actual JPQL IN parameter does not respect the batch size.

For example, with 250 identifiers:

Expected behavior:

  • 1st delete binds 100 identifiers
  • 2nd delete binds 100 identifiers
  • 3rd delete binds 50 identifiers

Current behavior:

  • 1st delete binds all 250 identifiers
  • 2nd delete binds all 250 identifiers again
  • 3rd delete binds all 250 identifiers again

The final deleted rows are usually the same, because the first query may delete all matching rows. However, the batching contract is not actually honored.

Impact

This is not a data correctness bug for normal cases where all requested identifiers should be deleted.

The risk appears when the method receives more than DELETE_BATCH_SIZE identifiers:

  • oversized IN parameters are sent to the database
  • the same large delete statement is repeated for every computed batch
  • database parameter limits can still be hit despite the batching code
  • query parsing/binding work grows unnecessarily for large delete requests

So the issue is best classified as a performance and operational stability fix.

Proposed Fix

Bind the current batch instead of the original identifier list:

batch(identifiers, DELETE_BATCH_SIZE).forEach(it -> {
    entityManager.createQuery(DELETE).setParameter(1, it).executeUpdate();
});

Test Coverage
Add a focused unit test for JpaEventPublicationRepository that verifies 101 identifiers are split into two delete executions with batch sizes 100 and 1.

Keep this as a unit test rather than adding mock-based verification to the existing integration test class, so it matches the repository's current test conventions.

Activity

  1. self-assigned this
    on May 21, 2026
  2. added this to the 2.1 GA milestone on May 21, 2026
  3. added 2 commits that reference this issue on Jun 10, 2026
  4. odrotbohm commented on Jun 10, 2026

    @odrotbohm
    Member

    That's applied, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions