Skip to content

Conversation

sami355-24
Copy link

This contribution improves the batch deletion functionality in JPA repositories by ensuring that both entities and their IDs passed to deleteAllInBatch and deleteAllByIdInBatch methods are properly handled within the persistence context.

related: #3360

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

… from the persistence context.

Added a test case to verify whether entities passed as arguments to the deleteAllInBatch method are properly removed from the persistence context in a JPA repository.
…removed from the persistence context.

Implemented logic to ensure that entities passed as arguments to the deleteAllInBatch method are properly removed from the persistence context in a JPA repository.

Added code to clear the EntityManager to prevent single delete queries from being issued to the database.
…ctly removed from the persistence context.

Added a test case to verify whether entity IDs passed as arguments to the deleteAllInBatch method are properly removed from the persistence context in a JPA repository.
…atch are properly handled in the persistence context.

Implemented logic to ensure that entities' IDs passed as arguments to the deleteAllByIdInBatch method are properly handled and removed from the persistence context in a JPA repository.

Added code to clear the EntityManager to prevent single delete queries from being issued to the database.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 24, 2024
Since the clear method on the entityManager is called after the loop, the code that detaches entities after calling remove inside the loop is unnecessary.
@mp911de mp911de self-assigned this Sep 9, 2024
@mp911de
Copy link
Member

mp911de commented Sep 9, 2024

Thanks for your pull request. Both Batch methods leverage delete queries to remove objects without loading them into memory (see also their Javadoc). This is an intentional design choice to perform removal as quickly as possible and without notifying listeners.

That being said, we want to keep the design as-is. Also, we cannot call EntityManager.clear(…) because that would remove all entities from the persistence context, potentially also these that require flushing.

@mp911de mp911de closed this Sep 9, 2024
@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I want to do a countribution where methods with batch keywords are processed through the persistence context.

3 participants