From ffafa1a3e30262815ce11952dcbdf2963613feff Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Thu, 9 Jan 2025 11:13:21 +0100 Subject: [PATCH] HHH-5689 Test rollback of flushed entity update and cache --- .../orm/test/cache/CacheModeGetUpdateTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cache/CacheModeGetUpdateTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cache/CacheModeGetUpdateTest.java index 70119bec9f7f..78676e54f7f0 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cache/CacheModeGetUpdateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cache/CacheModeGetUpdateTest.java @@ -13,6 +13,7 @@ import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.Jira; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.junit.jupiter.api.AfterAll; @@ -75,6 +76,22 @@ public void test(SessionFactoryScope scope) { } ); } + @Test + @Jira("https://hibernate.atlassian.net/browse/HHH-5689") + public void testRollback(SessionFactoryScope scope) { + scope.inTransaction( session -> { + final Phone phone = session.find( Phone.class, PHONE_ID ); + phone.setNumber( "456" ); + session.flush(); + session.markForRollbackOnly(); + } ); + // in a different transaction + scope.inTransaction( session -> { + final Phone phone = session.find( Phone.class, PHONE_ID ); + assertThat( phone.getNumber() ).isEqualTo( "123" ); + } ); + } + @Entity( name = "Phone" ) @Cacheable @Cache( usage = CacheConcurrencyStrategy.TRANSACTIONAL )