|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | + * Copyright Red Hat Inc. and Hibernate Authors |
| 4 | + */ |
| 5 | +package org.hibernate.orm.test.annotations.manytomany; |
| 6 | + |
| 7 | +import java.util.Collections; |
| 8 | +import java.util.HashSet; |
| 9 | +import java.util.Set; |
| 10 | + |
| 11 | +import org.hibernate.dialect.H2Dialect; |
| 12 | +import org.hibernate.testing.orm.junit.FailureExpected; |
| 13 | +import org.hibernate.testing.orm.junit.RequiresDialect; |
| 14 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 15 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 16 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | + |
| 20 | +/** |
| 21 | + * @author Jan Schatteman |
| 22 | + */ |
| 23 | +@RequiresDialect( value = H2Dialect.class ) |
| 24 | +@FailureExpected( jiraKey = "HHH-1914", reason = "throws an UnsupportedOperationException") |
| 25 | +@DomainModel( |
| 26 | + annotatedClasses = { |
| 27 | + Cat.class, Woman.class, Man.class |
| 28 | + } |
| 29 | +) |
| 30 | +@SessionFactory |
| 31 | +public class UnmodifiableCollectionMergeTest { |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testMergeUnmodifiableCollection(SessionFactoryScope scope) { |
| 35 | + scope.inTransaction( |
| 36 | + session -> { |
| 37 | + CatPk catPk = new CatPk(); |
| 38 | + catPk.setName( "Minou" ); |
| 39 | + catPk.setThoroughbred( "Persian" ); |
| 40 | + Cat cat = new Cat(); |
| 41 | + cat.setId( catPk ); |
| 42 | + |
| 43 | + WomanPk womanPk = new WomanPk(); |
| 44 | + womanPk.setFirstName( "Emma" ); |
| 45 | + womanPk.setLastName( "Peel" ); |
| 46 | + Woman woman = new Woman(); |
| 47 | + woman.setId( womanPk ); |
| 48 | + |
| 49 | + Set<Woman> women = new HashSet<>(); |
| 50 | + women.add( woman ); |
| 51 | + |
| 52 | + cat.setHumanContacts( Collections.unmodifiableSet( women ) ); |
| 53 | + Set<Cat> cats = new HashSet<>(); |
| 54 | + cats.add( cat ); |
| 55 | + woman.setCats( Collections.unmodifiableSet(cats) ); |
| 56 | + |
| 57 | + session.persist( cat ); |
| 58 | + session.persist( woman ); |
| 59 | + |
| 60 | + session.flush(); |
| 61 | + session.merge( woman ); |
| 62 | + } |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments