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;