|
| 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.inheritance; |
| 6 | + |
| 7 | +import jakarta.persistence.DiscriminatorColumn; |
| 8 | +import jakarta.persistence.DiscriminatorType; |
| 9 | +import jakarta.persistence.DiscriminatorValue; |
| 10 | +import jakarta.persistence.Embeddable; |
| 11 | +import jakarta.persistence.Embedded; |
| 12 | +import jakarta.persistence.Entity; |
| 13 | +import jakarta.persistence.GeneratedValue; |
| 14 | +import jakarta.persistence.Id; |
| 15 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 16 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 17 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 18 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +@DomainModel(annotatedClasses = { |
| 22 | + EmbeddableInheritanceReplaceTest.Emb.class, |
| 23 | + EmbeddableInheritanceReplaceTest.Base.class, |
| 24 | + EmbeddableInheritanceReplaceTest.Next.class, |
| 25 | + EmbeddableInheritanceReplaceTest.Ent.class |
| 26 | +}) |
| 27 | +@SessionFactory |
| 28 | +@JiraKey("HHH-19079") |
| 29 | +public class EmbeddableInheritanceReplaceTest { |
| 30 | + |
| 31 | + @Test |
| 32 | + void merge(SessionFactoryScope scope) { |
| 33 | + scope.inTransaction( session -> { |
| 34 | + final var history = new Ent(); |
| 35 | + history.setBase( new Emb( 42, "Hello, World!" ) ); |
| 36 | + |
| 37 | + session.merge( history ); |
| 38 | + } ); |
| 39 | + } |
| 40 | + |
| 41 | + @Embeddable |
| 42 | + @DiscriminatorValue("E") |
| 43 | + public static final class Emb extends Next { |
| 44 | + |
| 45 | + Emb() { |
| 46 | + } |
| 47 | + |
| 48 | + public Emb(int num, String str) { |
| 49 | + super( num, str ); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + @Embeddable |
| 54 | + @DiscriminatorColumn(name = "etype", discriminatorType = DiscriminatorType.CHAR) |
| 55 | + @DiscriminatorValue("b") |
| 56 | + public static class Base { |
| 57 | + |
| 58 | + protected int num; |
| 59 | + |
| 60 | + protected Base() { |
| 61 | + } |
| 62 | + |
| 63 | + public Base(int num, String str) { |
| 64 | + this.num = num; |
| 65 | + } |
| 66 | + |
| 67 | + public int getNum() { |
| 68 | + return num; |
| 69 | + } |
| 70 | + |
| 71 | + public void setNum(int num) { |
| 72 | + this.num = num; |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + @Embeddable |
| 77 | + @DiscriminatorValue("n") |
| 78 | + public static class Next extends Base { |
| 79 | + |
| 80 | + private String str; |
| 81 | + |
| 82 | + public Next(int num, String str) { |
| 83 | + super( num, str ); |
| 84 | + this.str = str; |
| 85 | + } |
| 86 | + |
| 87 | + public Next() { |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + @Entity(name = "Ent") |
| 92 | + public static class Ent { |
| 93 | + |
| 94 | + @Id |
| 95 | + @GeneratedValue |
| 96 | + private Integer id; |
| 97 | + |
| 98 | + @Embedded |
| 99 | + private Base base; |
| 100 | + |
| 101 | + public Ent() { |
| 102 | + } |
| 103 | + |
| 104 | + public Ent(final Integer id) { |
| 105 | + this.id = id; |
| 106 | + } |
| 107 | + |
| 108 | + public Integer getId() { |
| 109 | + return id; |
| 110 | + } |
| 111 | + |
| 112 | + public void setId(Integer id) { |
| 113 | + this.id = id; |
| 114 | + } |
| 115 | + |
| 116 | + public Base getBase() { |
| 117 | + return base; |
| 118 | + } |
| 119 | + |
| 120 | + public void setBase(Base base) { |
| 121 | + this.base = base; |
| 122 | + } |
| 123 | + } |
| 124 | +} |
0 commit comments