Skip to content

Commit 54ae7f0

Browse files
yrodierebeikov
authored andcommitted
HHH-19725 Test upsert for entity type that only declares an ID attribute
1 parent 1ad46ec commit 54ae7f0

File tree

1 file changed

+26
-2
lines changed
  • hibernate-core/src/test/java/org/hibernate/orm/test/stateless

1 file changed

+26
-2
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/stateless/UpsertTest.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import org.junit.jupiter.api.Test;
99

1010
import static org.junit.Assert.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1112

1213
@SessionFactory
13-
@DomainModel(annotatedClasses = UpsertTest.Record.class)
14+
@DomainModel(annotatedClasses = {UpsertTest.Record.class, UpsertTest.IdOnly.class})
1415
public class UpsertTest {
1516
@Test void test(SessionFactoryScope scope) {
1617
scope.inStatelessTransaction(s-> {
@@ -29,7 +30,18 @@ public class UpsertTest {
2930
assertEquals("hello mars",s.get(Record.class,456L).message);
3031
});
3132
}
32-
@Entity
33+
@Test void testIdOnly(SessionFactoryScope scope) {
34+
scope.inStatelessTransaction(s-> {
35+
s.upsert(new IdOnly(123L));
36+
s.upsert(new IdOnly(456L));
37+
});
38+
scope.inStatelessTransaction(s-> {
39+
assertNotNull(s.get( IdOnly.class,123L));
40+
assertNotNull(s.get( IdOnly.class,456L));
41+
});
42+
}
43+
44+
@Entity
3345
static class Record {
3446
@Id Long id;
3547
String message;
@@ -42,4 +54,16 @@ static class Record {
4254
Record() {
4355
}
4456
}
57+
58+
@Entity(name = "IdOnly")
59+
static class IdOnly {
60+
@Id Long id;
61+
62+
IdOnly(Long id) {
63+
this.id = id;
64+
}
65+
66+
IdOnly() {
67+
}
68+
}
4569
}

0 commit comments

Comments
 (0)