Skip to content

Commit 2931339

Browse files
mensindabeikov
authored andcommitted
HHH-19076 Add second composite key entity to the failing test
1 parent b3b20c9 commit 2931339

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/composite/CompositeInheritanceFailTest.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
CompositeInheritanceFailTest.TupAbstractEntity.class,
2829
CompositeInheritanceFailTest.DummyEntity.class,
2930
CompositeInheritanceFailTest.TestEntity.class, // Here the class is called TestEntity
31+
CompositeInheritanceFailTest.Test2Entity.class,
3032
}
3133
)
3234
@ServiceRegistry(
@@ -53,6 +55,18 @@ void hhh19076FailingTest(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
@@ -103,6 +117,39 @@ public CompositeIdClass getCompositeId() {
103117

104118
}
105119

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

108155
private String oid;
@@ -126,4 +173,27 @@ public String myId() {
126173

127174
}
128175

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
}

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)