HHH-14319 Create new collection rather than clearing original which is backing PersistentCollection entry of session

This commit is contained in:
Christian Beikov 2020-11-10 15:48:34 +01:00
parent 966d07c2d1
commit a975fbf5d4
2 changed files with 3 additions and 2 deletions

View File

@ -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

View File

@ -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<Comment> comments = new HashSet<>();
comments.add( new Comment( "abc", "me" ) );
bar.comments = comments;