Skip to content

Commit d30de2a

Browse files
committed
HHH-1914 - test case for UnsupportedOperationException upon merge of unmodifiable collection
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 8c1aa48 commit d30de2a

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.orm.test.annotations.manytomany;
8+
9+
import java.util.Collections;
10+
import java.util.HashSet;
11+
import java.util.Set;
12+
13+
import org.hibernate.dialect.H2Dialect;
14+
import org.hibernate.testing.orm.junit.FailureExpected;
15+
import org.hibernate.testing.RequiresDialect;
16+
import org.hibernate.testing.orm.junit.DomainModel;
17+
import org.hibernate.testing.orm.junit.SessionFactory;
18+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
/**
23+
* @author Jan Schatteman
24+
*/
25+
@RequiresDialect( value = H2Dialect.class )
26+
@FailureExpected( jiraKey = "HHH-1914", reason = "throws an UnsupportedOperationException")
27+
@DomainModel(
28+
annotatedClasses = {
29+
Cat.class, Woman.class, Man.class
30+
}
31+
)
32+
@SessionFactory
33+
public class UnmodifiableCollectionMergeTest {
34+
35+
@Test
36+
public void testMergeUnmodifiableCollection(SessionFactoryScope scope) {
37+
scope.inTransaction(
38+
session -> {
39+
CatPk catPk = new CatPk();
40+
catPk.setName( "Minou" );
41+
catPk.setThoroughbred( "Persian" );
42+
Cat cat = new Cat();
43+
cat.setId( catPk );
44+
45+
WomanPk womanPk = new WomanPk();
46+
womanPk.setFirstName( "Emma" );
47+
womanPk.setLastName( "Peel" );
48+
Woman woman = new Woman();
49+
woman.setId( womanPk );
50+
51+
Set<Woman> women = new HashSet<>();
52+
women.add( woman );
53+
54+
cat.setHumanContacts( Collections.unmodifiableSet( women ) );
55+
Set<Cat> cats = new HashSet<>();
56+
cats.add( cat );
57+
woman.setCats( Collections.unmodifiableSet(cats) );
58+
59+
session.persist( cat );
60+
session.persist( woman );
61+
62+
session.flush();
63+
session.merge( woman );
64+
}
65+
);
66+
}
67+
68+
}

0 commit comments

Comments
 (0)