#2952 #2953 - Fix for @OneToMany orphanRemoval not occurring

orphanRemoval was not occurring when a loaded bean had a collection
replaced by a new BeanCollection (as opposed to a vanilla collection
like java.util.ArrayList).

Json marshalling a collection puts beans into BeanCollection and this
is part of the test that reproduced this issue.
This commit is contained in:
Rob Bygrave committed 2023-02-09 23:29:13 +13:00
1 parent e01f19b3aa
commit 244d45674a
2 files changed
+31 -19

No files matched your search

@@ -37,6 +37,7 @@ final class SaveManyBeans extends SaveManyBase {
private final boolean hasOrderColumn;
private int sortOrder;
private boolean insertAllChildren;
private boolean forceOrphanRemoval;
SaveManyBeans(DefaultPersister persister, boolean insertedParent, BeanPropertyAssocMany<?> many, EntityBean parentBean, PersistRequestBean<?> request) {
super(persister, insertedParent, many, parentBean, request);
@@ -141,7 +142,7 @@ final class SaveManyBeans extends SaveManyBase {
}
private boolean forcedUpdateOrphanRemoval() {
return !insertedParent && many.isOrphanRemoval() && request.isForcedUpdate();
return !insertedParent && many.isOrphanRemoval() && (forceOrphanRemoval || request.isForcedUpdate());
}
private void saveAllBeans(final BeanProperty orderColumn) {
@@ -228,8 +229,10 @@ final class SaveManyBeans extends SaveManyBase {
if (detailBean instanceof EntityBean) {
Object id = targetDescriptor.id(detailBean);
if (!isNullOrZero(id)) {
// remember the Id (other details not in the collection) will be removed
detailIds.add(id);
if (!forceOrphanRemoval || !((EntityBean)detailBean)._ebean_getIntercept().isNew()) {
// remember the Id (other details not in the collection) will be removed
detailIds.add(id);
}
}
}
}
@@ -369,6 +372,8 @@ final class SaveManyBeans extends SaveManyBase {
}
}
}
} else {
forceOrphanRemoval = !insertedParent && isChangedProperty();
}
}
}