Skip to content

#3695 Use retainAll() for Set and Map instead of clear() #3696

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maxifridge
Copy link

@maxifridge maxifridge commented Sep 4, 2024

Implementation of #3695
Using retainAll() for Set and Map targets will minimize the amount of add/remove operations required for these types.
This limits side effects of removing preemptively all elements through clear() to non-Set Collections and Arrays.

A good example of why it is important (and the one that made me work on this issue) : when mapping to a Set property of a Hibernate-managed entity, calling clear() then addAll() effectively triggers requests for all deletions then all additions ; though because of the order of execution in Hibernate, only the newer elements are inserted, the others are deleted.

This limits side effects of removing preemptively all elements through clear() to non-Set Collections and Arrays.

A good example of why it is important is : when mapping to a Set property of a Hibernate-managed entity, calling clear() then addAll() effectively triggers requests for all deletions then all additions ; though because of the order of execution in Hiberante, only new elements are inserted.
@maxifridge maxifridge marked this pull request as draft September 4, 2024 09:38
@maxifridge maxifridge changed the title Use retainAll() for Set and Map instead of clear() #3695 Use retainAll() for Set and Map instead of clear() Sep 4, 2024
@maxifridge
Copy link
Author

This is still only a draft, it requires some cleaning/renaming, and certainly updating tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants