Skip to content

Commit 21330cc

Browse files
committed
HHH-19079 Test case showing the problem
1 parent 91cdac4 commit 21330cc

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.embeddableinheritancereplace;
6+
7+
import jakarta.persistence.DiscriminatorColumn;
8+
import jakarta.persistence.DiscriminatorType;
9+
import jakarta.persistence.DiscriminatorValue;
10+
import jakarta.persistence.Embeddable;
11+
12+
@Embeddable
13+
@DiscriminatorColumn(name = "etype", discriminatorType = DiscriminatorType.CHAR)
14+
@DiscriminatorValue("b")
15+
public class Base {
16+
17+
protected int num;
18+
19+
protected Base() {
20+
}
21+
22+
public Base(int num, String str) {
23+
this.num = num;
24+
}
25+
26+
public int getNum() {
27+
return num;
28+
}
29+
30+
public void setNum(int num) {
31+
this.num = num;
32+
}
33+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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.embeddableinheritancereplace;
6+
7+
import jakarta.persistence.DiscriminatorValue;
8+
import jakarta.persistence.Embeddable;
9+
10+
@Embeddable
11+
@DiscriminatorValue("E")
12+
public final class Emb extends Next {
13+
14+
Emb() {
15+
}
16+
17+
public Emb(int num, String str) {
18+
super(num, str);
19+
}
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.embeddableinheritancereplace;
6+
7+
import org.hibernate.testing.orm.junit.DomainModel;
8+
import org.hibernate.testing.orm.junit.JiraKey;
9+
import org.hibernate.testing.orm.junit.SessionFactory;
10+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
11+
import org.junit.jupiter.api.Test;
12+
13+
@DomainModel(annotatedClasses = {Emb.class, Base.class, Next.class, Ent.class})
14+
@SessionFactory
15+
@JiraKey( "HHH-19079" )
16+
public class EmbeddableInheritanceReplaceTest {
17+
18+
@Test
19+
void merge(SessionFactoryScope scope) {
20+
scope.inTransaction(session -> {
21+
final var history = new Ent();
22+
history.setBase(new Emb(42, "Hello, World!"));
23+
24+
session.merge(history);
25+
});
26+
}
27+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.embeddableinheritancereplace;
6+
7+
import jakarta.persistence.Embedded;
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.GeneratedValue;
10+
import jakarta.persistence.Id;
11+
12+
@Entity
13+
public class Ent {
14+
15+
@Id
16+
@GeneratedValue
17+
private Integer id;
18+
19+
@Embedded
20+
private Base base;
21+
22+
public Ent() {
23+
}
24+
25+
public Ent(final Integer id) {
26+
this.id = id;
27+
}
28+
29+
public Integer getId() {
30+
return id;
31+
}
32+
33+
public void setId(Integer id) {
34+
this.id = id;
35+
}
36+
37+
public Base getBase() {
38+
return base;
39+
}
40+
41+
public void setBase(Base base) {
42+
this.base = base;
43+
}
44+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.embeddableinheritancereplace;
6+
7+
import jakarta.persistence.DiscriminatorValue;
8+
import jakarta.persistence.Embeddable;
9+
10+
@Embeddable
11+
@DiscriminatorValue("n")
12+
public class Next extends Base {
13+
14+
private String str;
15+
16+
public Next(int num, String str) {
17+
super(num, str);
18+
this.str=str;
19+
}
20+
21+
public Next() {
22+
}
23+
}

0 commit comments

Comments
 (0)