From 3fe1f58c936a45aab18419128edee6c5c5d5cd43 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 9 Apr 2024 15:11:17 +0200 Subject: [PATCH] HHH-17934 test demonstrating bug Signed-off-by: Gavin King --- .../test/stateless/UpsertVersionedTest.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/stateless/UpsertVersionedTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/stateless/UpsertVersionedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/stateless/UpsertVersionedTest.java new file mode 100644 index 0000000000..1ae36bb72a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/stateless/UpsertVersionedTest.java @@ -0,0 +1,48 @@ +package org.hibernate.orm.test.stateless; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Version; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +@SessionFactory +@DomainModel(annotatedClasses = UpsertVersionedTest.Record.class) +public class UpsertVersionedTest { + @Test void test(SessionFactoryScope scope) { + scope.inStatelessTransaction(s-> { + s.upsert(new Record(123L,1L,"hello earth")); + s.upsert(new Record(456L,2L,"hello mars")); + }); + scope.inStatelessTransaction(s-> { + assertEquals("hello earth",s.get(Record.class,123L).message); + assertEquals("hello mars",s.get(Record.class,456L).message); + }); + scope.inStatelessTransaction(s-> { + s.upsert(new Record(123L,1L,"goodbye earth")); + }); + scope.inStatelessTransaction(s-> { + assertEquals("goodbye earth",s.get(Record.class,123L).message); + assertEquals("hello mars",s.get(Record.class,456L).message); + }); + } + @Entity + static class Record { + @Id Long id; + @Version Long version; + String message; + + Record(Long id, Long version, String message) { + this.id = id; + this.version = version; + this.message = message; + } + + Record() { + } + } +}