Skip to content

Commit cfdaead

Browse files
cigalymbladel
authored andcommitted
HHH-19079 Test case demonstrating the problem
1 parent c97cf47 commit cfdaead

File tree

1 file changed

+119
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)