Skip to content

Commit ffb7ba6

Browse files
committed
HHH-19076 Add second composite key entity to the failing test
1 parent 89ffdba commit ffb7ba6

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/composite/CompositeInheritanceFailTest.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
CompositeInheritanceFailTest.TupAbstractEntity.class,
2828
CompositeInheritanceFailTest.DummyEntity.class,
2929
CompositeInheritanceFailTest.TestEntity.class, // Here the class is called TestEntity
30+
CompositeInheritanceFailTest.Test2Entity.class,
3031
}
3132
)
3233
@ServiceRegistry(
@@ -53,6 +54,18 @@ void hhh19076FailingTest(SessionFactoryScope scope) {
5354
} );
5455
}
5556

57+
@Test
58+
void hhh19076FailingTest2(SessionFactoryScope scope) {
59+
scope.inTransaction( em -> {
60+
Test2Entity e1 = new Test2Entity("foo", "xxxxxx");
61+
em.persist(e1);
62+
63+
CompositeId2Class key = e1.getCompositeId();
64+
Test2Entity e2 = em.find(Test2Entity.class, key);
65+
assertNotNull(e2);
66+
} );
67+
}
68+
5669
@MappedSuperclass
5770
public static abstract class TupAbstractEntity {
5871
@Id
@@ -103,6 +116,32 @@ public CompositeIdClass getCompositeId() {
103116

104117
}
105118

119+
@Entity
120+
@IdClass(CompositeId2Class.class)
121+
public static class Test2Entity extends TupAbstractEntity {
122+
123+
@Id
124+
private String otherId;
125+
126+
protected Test2Entity() {
127+
// for JPA
128+
}
129+
130+
public Test2Entity(String oid, String otherId) {
131+
super(oid);
132+
this.otherId = otherId;
133+
}
134+
135+
public String myId() {
136+
return otherId;
137+
}
138+
139+
public CompositeId2Class getCompositeId() {
140+
return new CompositeId2Class(getOid(), otherId);
141+
}
142+
143+
}
144+
106145
public static class CompositeIdClass {
107146

108147
private String oid;
@@ -126,4 +165,27 @@ public String myId() {
126165

127166
}
128167

168+
public static class CompositeId2Class {
169+
170+
private String oid;
171+
private String otherId;
172+
173+
public CompositeId2Class(String oid, String otherId) {
174+
this.oid = oid;
175+
this.otherId = otherId;
176+
}
177+
178+
public CompositeId2Class() {
179+
}
180+
181+
public String oid() {
182+
return oid;
183+
}
184+
185+
public String otherId() {
186+
return otherId;
187+
}
188+
189+
}
190+
129191
}

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/composite/CompositeInheritanceWorkingTest.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import jakarta.persistence.Id;
99
import jakarta.persistence.IdClass;
1010
import jakarta.persistence.MappedSuperclass;
11+
import jakarta.persistence.Version;
1112
import org.hibernate.cfg.AvailableSettings;
1213
import org.hibernate.testing.orm.junit.DomainModel;
1314
import org.hibernate.testing.orm.junit.Jira;
@@ -27,6 +28,7 @@
2728
CompositeInheritanceWorkingTest.TupAbstractEntity.class,
2829
CompositeInheritanceWorkingTest.DummyEntity.class,
2930
CompositeInheritanceWorkingTest.FooEntity.class, // And here the class is called FooEntity and this works for some reason
31+
CompositeInheritanceWorkingTest.Test2Entity.class,
3032
}
3133
)
3234
@ServiceRegistry(
@@ -53,11 +55,26 @@ void hhh19076WorkingTest(SessionFactoryScope scope) {
5355
} );
5456
}
5557

58+
@Test
59+
void hhh19076FailingTest2(SessionFactoryScope scope) {
60+
scope.inTransaction( em -> {
61+
Test2Entity e1 = new Test2Entity("foo", "xxxxxx");
62+
em.persist(e1);
63+
64+
CompositeId2Class key = e1.getCompositeId();
65+
Test2Entity e2 = em.find( Test2Entity.class, key);
66+
assertNotNull(e2);
67+
} );
68+
}
69+
5670
@MappedSuperclass
5771
public static abstract class TupAbstractEntity {
5872
@Id
5973
private String oid = null;
6074

75+
@Version
76+
private long tanum = 0;
77+
6178

6279
@SuppressWarnings("this-escape")
6380
protected TupAbstractEntity() {
@@ -71,6 +88,9 @@ public String getOid() {
7188
return oid;
7289
}
7390

91+
public long getTanum() {
92+
return tanum;
93+
}
7494
}
7595

7696
@Entity
@@ -103,6 +123,32 @@ public CompositeIdClass getCompositeId() {
103123

104124
}
105125

126+
@Entity
127+
@IdClass(CompositeId2Class.class)
128+
public static class Test2Entity extends TupAbstractEntity {
129+
130+
@Id
131+
private String otherId;
132+
133+
protected Test2Entity() {
134+
// for JPA
135+
}
136+
137+
public Test2Entity(String oid, String otherId) {
138+
super(oid);
139+
this.otherId = otherId;
140+
}
141+
142+
public String myId() {
143+
return otherId;
144+
}
145+
146+
public CompositeId2Class getCompositeId() {
147+
return new CompositeId2Class(getOid(), otherId);
148+
}
149+
150+
}
151+
106152
public static class CompositeIdClass {
107153

108154
private String oid;
@@ -126,4 +172,28 @@ public String myId() {
126172

127173
}
128174

175+
176+
public static class CompositeId2Class {
177+
178+
private String oid;
179+
private String otherId;
180+
181+
public CompositeId2Class(String oid, String otherId) {
182+
this.oid = oid;
183+
this.otherId = otherId;
184+
}
185+
186+
public CompositeId2Class() {
187+
}
188+
189+
public String oid() {
190+
return oid;
191+
}
192+
193+
public String otherId() {
194+
return otherId;
195+
}
196+
197+
}
198+
129199
}

0 commit comments

Comments
 (0)