Skip to content

Commit 2abbaad

Browse files
yrodierebeikov
authored andcommitted
HHH-19725 Test upsert for entity type that only declares an ID attribute
1 parent 2269a00 commit 2abbaad

File tree

1 file changed

+27
-1
lines changed
  • hibernate-core/src/test/java/org/hibernate/orm/test/stateless

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2020
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2122

2223
@SessionFactory(useCollectingStatementInspector = true)
23-
@DomainModel(annotatedClasses = UpsertTest.Record.class)
24+
@DomainModel(annotatedClasses = {UpsertTest.Record.class, UpsertTest.IdOnly.class})
2425
public class UpsertTest {
2526
@Test void test(SessionFactoryScope scope) {
2627
scope.getSessionFactory().getSchemaManager().truncate();
@@ -96,6 +97,19 @@ public class UpsertTest {
9697
scope.inStatelessTransaction(s-> assertDoesNotThrow(() -> s.upsert(new Record(123L,null, null))) );
9798
}
9899

100+
@Test void testIdOnly(SessionFactoryScope scope) {
101+
scope.getSessionFactory().getSchemaManager().truncate();
102+
103+
scope.inStatelessTransaction(s-> {
104+
s.upsert(new IdOnly(123L));
105+
s.upsert(new IdOnly(456L));
106+
});
107+
scope.inStatelessTransaction(s-> {
108+
assertNotNull(s.get( IdOnly.class,123L));
109+
assertNotNull(s.get( IdOnly.class,456L));
110+
});
111+
}
112+
99113
@Entity(name = "Record")
100114
static class Record {
101115
@Id Long id;
@@ -116,4 +130,16 @@ static class Record {
116130
Record() {
117131
}
118132
}
133+
134+
@Entity(name = "IdOnly")
135+
static class IdOnly {
136+
@Id Long id;
137+
138+
IdOnly(Long id) {
139+
this.id = id;
140+
}
141+
142+
IdOnly() {
143+
}
144+
}
119145
}

0 commit comments

Comments
 (0)