From d2f16cbf6a7bb4e1a6a5939584fe205896f9b84d Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Fri, 9 Feb 2024 15:24:47 +1300 Subject: [PATCH] #3310 Fix for orphanRemoval with updated parent and 'vanilla collection' The issue fixed here is a timing one where the parent bean is being updated. The updated parent bean has its internal state reset before the cascade down to the SaveManyBeans where for this case it needs to identify is the 'vanilla' collection has set (via setChildren(new ArrayList()). This fix is a change that for updated beans the dirtyProperties is always obtained and then use this for the isChangedProperty() check. --- .../server/core/PersistRequestBean.java | 12 ++++++++++-- .../ebeaninternal/server/persist/SaveManyBeans.java | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java index 2d3a30bb5..6682754cb 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java @@ -380,6 +380,14 @@ public final class PersistRequestBean extends PersistRequest implements BeanP return intercept.dirtyPropertyNames(); } + public boolean isChangedProperty(int propertyIndex) { + if (dirtyProperties == null) { + return intercept.isChangedProperty(propertyIndex); + } else { + return dirtyProperties[propertyIndex]; + } + } + /** * Return the dirty properties on this request. */ @@ -865,8 +873,8 @@ public final class PersistRequestBean extends PersistRequest implements BeanP } setNotifyCache(); boolean isChangeLog = beanDescriptor.isChangeLog(); - if (type == Type.UPDATE && (isChangeLog || notifyCache || docStoreMode == DocStoreMode.UPDATE)) { - // get the dirty properties for update notification to the doc store + if (type == Type.UPDATE) { + // get the dirty properties for notify cache & orphanRemoval of vanilla collection detection dirtyProperties = intercept.dirtyProperties(); } if (isChangeLog) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java index e3ccabbff..e82c16961 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java @@ -328,7 +328,7 @@ final class SaveManyBeans extends SaveManyBase { } private boolean isChangedProperty() { - return parentBean._ebean_getIntercept().isChangedProperty(many.propertyIndex()); + return request.isChangedProperty(many.propertyIndex()); } private void removeAssocManyOrphans() {