|
| 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.bytecode.enhancement.dynamic; |
| 6 | + |
| 7 | +import jakarta.persistence.Entity; |
| 8 | +import jakarta.persistence.FetchType; |
| 9 | +import jakarta.persistence.GeneratedValue; |
| 10 | +import jakarta.persistence.Id; |
| 11 | +import jakarta.persistence.ManyToOne; |
| 12 | +import jakarta.persistence.OneToMany; |
| 13 | +import jakarta.persistence.Version; |
| 14 | +import org.hibernate.annotations.LazyGroup; |
| 15 | +import org.hibernate.persister.entity.EntityPersister; |
| 16 | +import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced; |
| 17 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 18 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 19 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 20 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +import java.util.HashSet; |
| 24 | +import java.util.Set; |
| 25 | + |
| 26 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
| 27 | + |
| 28 | + |
| 29 | +@JiraKey("HHH-15186") |
| 30 | +@BytecodeEnhanced |
| 31 | +@DomainModel( |
| 32 | + annotatedClasses = { |
| 33 | + DynamicStatusWithMultipleToManyRelationTest.FooEntity.class, |
| 34 | + DynamicStatusWithMultipleToManyRelationTest.BarEntity.class, |
| 35 | + DynamicStatusWithMultipleToManyRelationTest.BazEntity.class |
| 36 | + } |
| 37 | +) |
| 38 | +@SessionFactory |
| 39 | +public class DynamicStatusWithMultipleToManyRelationTest { |
| 40 | + |
| 41 | + @Test |
| 42 | + public void test(SessionFactoryScope scope) { |
| 43 | + final EntityPersister persister = scope.getSessionFactory().getMappingMetamodel() |
| 44 | + .findEntityDescriptor( FooEntity.class ); |
| 45 | + assertThat( persister.getEntityMetamodel().isDynamicUpdate() ).isFalse(); |
| 46 | + } |
| 47 | + |
| 48 | + @Entity(name = "FooEntity") |
| 49 | + public static class FooEntity { |
| 50 | + |
| 51 | + @Id |
| 52 | + private long id; |
| 53 | + @Version |
| 54 | + private int version; |
| 55 | + |
| 56 | + private String name; |
| 57 | + |
| 58 | + @LazyGroup("bars") |
| 59 | + @OneToMany(mappedBy = "foo") |
| 60 | + public Set<BarEntity> bars = new HashSet<>(); |
| 61 | + |
| 62 | + @LazyGroup("bazzes") |
| 63 | + @OneToMany(mappedBy = "foo") |
| 64 | + public Set<BazEntity> bazzes = new HashSet<>(); |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | + @Entity(name = "BazEntity") |
| 69 | + public static class BazEntity { |
| 70 | + |
| 71 | + @Id |
| 72 | + @GeneratedValue |
| 73 | + private long id; |
| 74 | + |
| 75 | + @ManyToOne(fetch = FetchType.LAZY, optional = false) |
| 76 | + private FooEntity foo; |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + @Entity(name = "BarEntity") |
| 81 | + public static class BarEntity { |
| 82 | + |
| 83 | + @Id |
| 84 | + @GeneratedValue |
| 85 | + private long id; |
| 86 | + |
| 87 | + @ManyToOne(fetch = FetchType.LAZY, optional = false) |
| 88 | + private FooEntity foo; |
| 89 | + |
| 90 | + } |
| 91 | +} |
0 commit comments