Skip to content

Commit 306e59b

Browse files
gavinkingbeikov
authored andcommitted
HHH-17934 test demonstrating bug
Signed-off-by: Gavin King <gavin@hibernate.org>
1 parent 87735be commit 306e59b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.hibernate.orm.test.stateless;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.Id;
5+
import jakarta.persistence.Version;
6+
import org.hibernate.testing.orm.junit.DomainModel;
7+
import org.hibernate.testing.orm.junit.SessionFactory;
8+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
9+
import org.junit.jupiter.api.Test;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
@SessionFactory
14+
@DomainModel(annotatedClasses = UpsertVersionedTest.Record.class)
15+
public class UpsertVersionedTest {
16+
@Test void test(SessionFactoryScope scope) {
17+
scope.inStatelessTransaction(s-> {
18+
s.upsert(new Record(123L,1L,"hello earth"));
19+
s.upsert(new Record(456L,2L,"hello mars"));
20+
});
21+
scope.inStatelessTransaction(s-> {
22+
assertEquals("hello earth",s.get(Record.class,123L).message);
23+
assertEquals("hello mars",s.get(Record.class,456L).message);
24+
});
25+
scope.inStatelessTransaction(s-> {
26+
s.upsert(new Record(123L,1L,"goodbye earth"));
27+
});
28+
scope.inStatelessTransaction(s-> {
29+
assertEquals("goodbye earth",s.get(Record.class,123L).message);
30+
assertEquals("hello mars",s.get(Record.class,456L).message);
31+
});
32+
}
33+
@Entity
34+
static class Record {
35+
@Id Long id;
36+
@Version Long version;
37+
String message;
38+
39+
Record(Long id, Long version, String message) {
40+
this.id = id;
41+
this.version = version;
42+
this.message = message;
43+
}
44+
45+
Record() {
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)