Skip to content

Commit fa4dfb5

Browse files
mensindabeikov
authored andcommitted
HHH-19076 Reproducer testcase
1 parent dfbd0bd commit fa4dfb5

File tree

2 files changed

+258
-0
lines changed

2 files changed

+258
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.mapping.identifier.composite;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.IdClass;
10+
import jakarta.persistence.MappedSuperclass;
11+
import org.hibernate.cfg.AvailableSettings;
12+
import org.hibernate.testing.orm.junit.DomainModel;
13+
import org.hibernate.testing.orm.junit.Jira;
14+
import org.hibernate.testing.orm.junit.ServiceRegistry;
15+
import org.hibernate.testing.orm.junit.SessionFactory;
16+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
17+
import org.hibernate.testing.orm.junit.Setting;
18+
import org.junit.jupiter.api.Test;
19+
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
22+
/**
23+
* This test Fails
24+
*/
25+
@DomainModel(
26+
annotatedClasses = {
27+
CompositeInheritanceFailTest.TupAbstractEntity.class,
28+
CompositeInheritanceFailTest.DummyEntity.class,
29+
CompositeInheritanceFailTest.TestEntity.class, // Here the class is called TestEntity
30+
}
31+
)
32+
@ServiceRegistry(
33+
settings = {
34+
// For your own convenience to see generated queries:
35+
@Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
36+
@Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
37+
// @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
38+
}
39+
)
40+
@SessionFactory
41+
@Jira("HHH-19076")
42+
public class CompositeInheritanceFailTest {
43+
44+
@Test
45+
void hhh19076FailingTest(SessionFactoryScope scope) {
46+
scope.inTransaction( em -> {
47+
TestEntity e1 = new TestEntity("foo", "bar");
48+
em.persist(e1);
49+
50+
CompositeIdClass key = e1.getCompositeId();
51+
TestEntity e2 = em.find(TestEntity.class, key);
52+
assertNotNull(e2);
53+
} );
54+
}
55+
56+
@MappedSuperclass
57+
public static abstract class TupAbstractEntity {
58+
@Id
59+
private String oid = null;
60+
61+
62+
@SuppressWarnings("this-escape")
63+
protected TupAbstractEntity() {
64+
}
65+
66+
protected TupAbstractEntity(String oid) {
67+
this.oid = oid;
68+
}
69+
70+
public String getOid() {
71+
return oid;
72+
}
73+
74+
}
75+
76+
@Entity
77+
public static class DummyEntity extends TupAbstractEntity {
78+
}
79+
80+
@Entity
81+
@IdClass(CompositeIdClass.class)
82+
public static class TestEntity extends TupAbstractEntity {
83+
84+
@Id
85+
private String myId;
86+
87+
protected TestEntity() {
88+
// for JPA
89+
}
90+
91+
public TestEntity(String oid, String myId) {
92+
super(oid);
93+
this.myId = myId;
94+
}
95+
96+
public String myId() {
97+
return myId;
98+
}
99+
100+
public CompositeIdClass getCompositeId() {
101+
return new CompositeIdClass(getOid(), myId);
102+
}
103+
104+
}
105+
106+
public static class CompositeIdClass {
107+
108+
private String oid;
109+
private String myId;
110+
111+
public CompositeIdClass(String oid, String myId) {
112+
this.oid = oid;
113+
this.myId = myId;
114+
}
115+
116+
public CompositeIdClass() {
117+
}
118+
119+
public String oid() {
120+
return oid;
121+
}
122+
123+
public String myId() {
124+
return myId;
125+
}
126+
127+
}
128+
129+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.mapping.identifier.composite;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.IdClass;
10+
import jakarta.persistence.MappedSuperclass;
11+
import org.hibernate.cfg.AvailableSettings;
12+
import org.hibernate.testing.orm.junit.DomainModel;
13+
import org.hibernate.testing.orm.junit.Jira;
14+
import org.hibernate.testing.orm.junit.ServiceRegistry;
15+
import org.hibernate.testing.orm.junit.SessionFactory;
16+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
17+
import org.hibernate.testing.orm.junit.Setting;
18+
import org.junit.jupiter.api.Test;
19+
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
22+
/**
23+
* This test works for some reason...
24+
*/
25+
@DomainModel(
26+
annotatedClasses = {
27+
CompositeInheritanceWorkingTest.TupAbstractEntity.class,
28+
CompositeInheritanceWorkingTest.DummyEntity.class,
29+
CompositeInheritanceWorkingTest.FooEntity.class, // And here the class is called FooEntity and this works for some reason
30+
}
31+
)
32+
@ServiceRegistry(
33+
settings = {
34+
// For your own convenience to see generated queries:
35+
@Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
36+
@Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
37+
// @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
38+
}
39+
)
40+
@SessionFactory
41+
@Jira("HHH-19076")
42+
public class CompositeInheritanceWorkingTest {
43+
44+
@Test
45+
void hhh19076WorkingTest(SessionFactoryScope scope) {
46+
scope.inTransaction( em -> {
47+
FooEntity e1 = new FooEntity("foo", "bar");
48+
em.persist(e1);
49+
50+
CompositeIdClass key = e1.getCompositeId();
51+
FooEntity e2 = em.find( FooEntity.class, key);
52+
assertNotNull(e2);
53+
} );
54+
}
55+
56+
@MappedSuperclass
57+
public static abstract class TupAbstractEntity {
58+
@Id
59+
private String oid = null;
60+
61+
62+
@SuppressWarnings("this-escape")
63+
protected TupAbstractEntity() {
64+
}
65+
66+
protected TupAbstractEntity(String oid) {
67+
this.oid = oid;
68+
}
69+
70+
public String getOid() {
71+
return oid;
72+
}
73+
74+
}
75+
76+
@Entity
77+
public static class DummyEntity extends TupAbstractEntity {
78+
}
79+
80+
@Entity
81+
@IdClass(CompositeIdClass.class)
82+
public static class FooEntity extends TupAbstractEntity {
83+
84+
@Id
85+
private String myId;
86+
87+
protected FooEntity() {
88+
// for JPA
89+
}
90+
91+
public FooEntity(String oid, String myId) {
92+
super(oid);
93+
this.myId = myId;
94+
}
95+
96+
public String myId() {
97+
return myId;
98+
}
99+
100+
public CompositeIdClass getCompositeId() {
101+
return new CompositeIdClass(getOid(), myId);
102+
}
103+
104+
}
105+
106+
public static class CompositeIdClass {
107+
108+
private String oid;
109+
private String myId;
110+
111+
public CompositeIdClass(String oid, String myId) {
112+
this.oid = oid;
113+
this.myId = myId;
114+
}
115+
116+
public CompositeIdClass() {
117+
}
118+
119+
public String oid() {
120+
return oid;
121+
}
122+
123+
public String myId() {
124+
return myId;
125+
}
126+
127+
}
128+
129+
}

0 commit comments

Comments
 (0)