#2127 - Fix for - Adding a new list of children to @OneToMany with orphanRemoval true does not delete existing orphans

Modifies EntityBeanIntercept preSetterMany to set the changed state on the many property and use this in SaveManyBeans to detect when the existing beans need orphan removal
This commit is contained in:
Robin Bygrave committed 2021-02-04 15:45:19 +13:00
1 parent dd080c5933
commit d57657c209
4 files changed
+79 -20

No files matched your search

@@ -210,18 +210,6 @@ public class SaveManyBeans extends SaveManyBase {
return true;
}
private boolean hasNewOrDirtyBeans() {
if (collection == null) {
return false;
}
for (Object bean : collection) {
if (bean instanceof EntityBean && ((EntityBean) bean)._ebean_getIntercept().isNewOrDirty()) {
return true;
}
}
return false;
}
/**
* Collect the Id values of the details to remove 'missing children' for stateless updates.
*/
@@ -344,14 +332,18 @@ public class SaveManyBeans extends SaveManyBase {
transaction.depth(-1);
}
private boolean isChangedProperty() {
return parentBean._ebean_getIntercept().isChangedProperty(many.getPropertyIndex());
}
private void removeAssocManyOrphans() {
if (value == null) {
return;
}
if (!(value instanceof BeanCollection<?>)) {
// if (!insertedParent && cascade && hasNewOrDirtyBeans()) {
// persister.addToFlushQueue(many.deleteByParentId(request.getBeanId(), null), transaction, 0);
// }
if (!insertedParent && cascade && isChangedProperty()) {
persister.addToFlushQueue(many.deleteByParentId(request.getBeanId(), null), transaction, 0);
}
} else {
BeanCollection<?> c = (BeanCollection<?>) value;
Set<?> modifyRemovals = c.getModifyRemovals();