Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,19 @@ private Object replaceOriginal(
final boolean wasClean =
target instanceof PersistentCollection<?> collection
&& !collection.isDirty();
if ( target instanceof PersistentCollection<?> existingPersistentCollection
&& existingPersistentCollection.isDirectlyAccessible() ) {
// When a replace/merge is requested and the underlying collection is directly accessible,
// use a new persistent collection, to avoid potential issues
// like the underlying collection being unmodifiable and hence failing the element replacement
final CollectionPersister collectionPersister = getPersister( session );
final Object key = existingPersistentCollection.getKey();
final PersistentCollection<?> persistentCollection = instantiate( session, collectionPersister, key );
persistentCollection.initializeEmptyCollection( collectionPersister );
persistentCollection.setSnapshot( key, existingPersistentCollection.getRole(), existingPersistentCollection.getStoredSnapshot() );
session.getPersistenceContextInternal().addInitializedDetachedCollection( collectionPersister, persistentCollection );
target = persistentCollection;
}
//TODO: this is a little inefficient, don't need to do a whole
// deep replaceElements() call
replaceElements( result, target, owner, copyCache, session );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Set;

import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
Expand All @@ -21,7 +20,6 @@
* @author Jan Schatteman
*/
@RequiresDialect( value = H2Dialect.class )
@FailureExpected( jiraKey = "HHH-1914", reason = "throws an UnsupportedOperationException")
@DomainModel(
annotatedClasses = {
Cat.class, Woman.class, Man.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ public void testMergeManaged(SessionFactoryScope scope) {
session.getTransaction().commit();

assertInsertCount( 1, scope );
assertUpdateCount( 0, scope );
assertUpdateCount( 1, scope );

assertThat( root.getChildren().size(), is( 1 ) );
assertTrue( root.getChildren().contains( mergedChild ) );
Expand Down
Loading