Merge pull request #2960 from ebean-orm/buchtajz-one2many_setArraylist

Fix for @OneToMany orphanRemoval not occurring for #2952 #2953
This commit is contained in:
Rob Bygrave authored and GitHub committed 2023-02-10 13:01:55 +13:00
commit 889c0f12e0
5 files changed
+101 -17

No files matched your search

@@ -38,13 +38,10 @@ public final class BeanCollectionUtil {
// returns a collection of beans
return bc.getActualEntries();
}
if (o instanceof Map<?, ?>) {
// yes, we want the entrySet (to set the keys)
return ((Map<?, ?>) o).entrySet();
} else if (o instanceof Collection<?>) {
if (o instanceof Collection<?>) {
return ((Collection<?>) o);
} else if (o instanceof Map<?, ?>) {
return ((Map<?, ?>) o).entrySet();
}
throw new PersistenceException("expecting a Map or Collection but got " + o.getClass().getName());
}
@@ -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);
}
}
}
}
@@ -359,7 +362,9 @@ final class SaveManyBeans extends SaveManyBase {
if (!hasOrderColumn) {
c.modifyReset();
}
if (modifyRemovals != null && !modifyRemovals.isEmpty()) {
if (modifyRemovals == null || modifyRemovals.isEmpty()) {
forceOrphanRemoval = !insertedParent && isChangedProperty();
} else {
for (Object removedBean : modifyRemovals) {
if (removedBean instanceof EntityBean) {
EntityBean eb = (EntityBean) removedBean;