Repository navigation
Conversation
For a hard delete, when the descriptor and every cascaded bean can be removed in bulk, the fetched beans' non-null imported target ids are grouped by type in first-seen order and relationships that share a type share one delete. Children and these owners are deleted via deleteChildrenAndBeans, which does not fetch imported relationships again; the transaction is flushed so owner deletes hit the database before the referenced beans are removed; then each imported type is deleted from its collected ids. An empty fetch returns 0. Multi-tenant descriptors, soft delete, descriptors that are not delete-by-bulk, and a descriptor still on the stack (a cycle) stay on the per-bean cascade; many-to-many and element collections are not walked by the eligibility check, and a descriptor already accepted is not walked again. Fixes ebean-orm#1750
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
A cascaded permanent delete of a parent whose children own relationships to other beans issues a separate delete for every child and every related bean. Cascades under those related beans run once per bean, and the statement count grows with the size of the graph.
Delete-by-id for a bean with owning-side cascade relationships loads the rows and then calls deleteCascade on that list, walking one bean at a time. Imported targets are followed per bean, so two associations to the same type are never merged into one id set and each target loads and deletes its own children again. Nothing in that walk collects the ids for a bulk delete.
What this changes
For a hard delete, when the descriptor and every cascaded bean can be removed in bulk:
These stay on the per-bean cascade: multi-tenant descriptors, soft delete, descriptors that are not delete-by-bulk, and a descriptor still on the stack (a cycle). Many-to-many and element collections are not walked by the eligibility check, and a descriptor already accepted is not walked again.
How it was tested
mvn -B -ntp -pl ebean-test -am test -Dtest=TestPersistCascade -Dsurefire.failIfNoSpecifiedTests=falsepassed 7 tests locally and in a Linux container (maven:3-eclipse-temurin-21). The tests inebean-test/src/test/java/org/tests/iud/TestPersistCascade.javafail without the fix (checked by reverting the source changes). The ebean-querybean tests also pass locally on this branch.Fixes #1750