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

Follow up #3173 - Change BeanSet clear() with orphanRemoval to lazy load ALL properties (avoid 1+N) #3205

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

rbygrave
Copy link
Member

@rbygrave rbygrave commented Aug 29, 2023

Scenario:
set.clear() on a Set with orphanRemoval = true

Currently the clear() invokes lazy loads only fetching the Id properties but this is problematic when the entity bean in the Set has a hashcode/equals implementation as it results in 1 + N queries. That is, for orphan removal it is identifying the beans that are going to be deleted and when doing that (with only the Id property fetched) the hashcode/equals implementation is invoked and that then invokes lazy loading N times where N is the number of elements in the collection that is being cleared.

To avoid the 1+N lazy loading queries instead the clear() invokes lazy loading that includes ALL the properties such that equals/hashcode implementation does not itself invoke lazy loading.

To be awesome, ebean would detect the properties that are used in hashcode/equals implementation and only fetch the Id property and those properties involved in the hashcode/equals for this case (rather than all properties). This might be a future optimisation that we could pursue using the entity bean enhancement to detect those properties used in the hashcode/equals.

To avoid the 1+N lazy loading queries that are invoked due to the clear()
when the entity bean in the Set has a hashCode/equals implementation
@rbygrave rbygrave self-assigned this Aug 29, 2023
@rbygrave rbygrave added this to the 13.22.0 milestone Aug 29, 2023
@rbygrave rbygrave merged commit 180b4d6 into master Aug 29, 2023
2 checks passed
@rbygrave rbygrave deleted the feature/3173-beanSet-clear branch August 29, 2023 10:02
@rbygrave rbygrave changed the title Follow up #3173 - Change BeanSet clear() to lazy load ALL properties Follow up #3173 - Change BeanSet clear() with orphanRemoval to lazy load ALL properties (avoid 1+N) Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant