HHH-1914 - test case for UnsupportedOperationException upon merge of unmodifiable collection

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2022-11-11 19:58:46 +01:00 committed by Jan Schatteman
parent d3a1ebd0e2
commit 23109af6e4
1 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,66 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.annotations.manytomany;
import java.util.Collections;
import java.util.HashSet;
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;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
/**
* @author Jan Schatteman
*/
@RequiresDialect( value = H2Dialect.class )
@FailureExpected( jiraKey = "HHH-1914", reason = "throws an UnsupportedOperationException")
@DomainModel(
annotatedClasses = {
Cat.class, Woman.class, Man.class
}
)
@SessionFactory
public class UnmodifiableCollectionMergeTest {
@Test
public void testMergeUnmodifiableCollection(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
CatPk catPk = new CatPk();
catPk.setName( "Minou" );
catPk.setThoroughbred( "Persian" );
Cat cat = new Cat();
cat.setId( catPk );
WomanPk womanPk = new WomanPk();
womanPk.setFirstName( "Emma" );
womanPk.setLastName( "Peel" );
Woman woman = new Woman();
woman.setId( womanPk );
Set<Woman> women = new HashSet<>();
women.add( woman );
cat.setHumanContacts( Collections.unmodifiableSet( women ) );
Set<Cat> cats = new HashSet<>();
cats.add( cat );
woman.setCats( Collections.unmodifiableSet(cats) );
session.persist( cat );
session.persist( woman );
session.flush();
session.merge( woman );
}
);
}
}