From a975fbf5d40dce7b8c4778d3cc2baa1b2872fe87 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Tue, 10 Nov 2020 15:48:34 +0100 Subject: [PATCH] HHH-14319 Create new collection rather than clearing original which is backing PersistentCollection entry of session --- .../src/main/java/org/hibernate/type/CollectionType.java | 3 ++- .../annotations/selectbeforeupdate/UpdateDetachedTest.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java index 18d3bdd342..1f4ac97ab3 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java @@ -742,7 +742,8 @@ public abstract class CollectionType extends AbstractType implements Association // need to put the merged elements in a new collection Object result = ( target == null || target == original || - target == LazyPropertyInitializer.UNFETCHED_PROPERTY ) ? + target == LazyPropertyInitializer.UNFETCHED_PROPERTY || + target instanceof PersistentCollection && ( (PersistentCollection) target ).isWrapper( original ) ) ? instantiateResult( original ) : target; //for arrays, replaceElements() may return a different reference, since diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/selectbeforeupdate/UpdateDetachedTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/selectbeforeupdate/UpdateDetachedTest.java index e08719b4d1..673607968f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/selectbeforeupdate/UpdateDetachedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/selectbeforeupdate/UpdateDetachedTest.java @@ -143,7 +143,7 @@ public class UpdateDetachedTest extends BaseCoreFunctionalTestCase{ @Test @TestForIssue(jiraKey = "HHH-14319") public void testUpdateDetachedWithAttachedPersistentSet() { - final Bar bar = new Bar( 4, "Bar" ); + final Bar bar = new Bar( 5, "Bar" ); final Set comments = new HashSet<>(); comments.add( new Comment( "abc", "me" ) ); bar.comments = comments;