From 3da12cae6132a71991d3e81a76036d9a03a37379 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Thu, 7 Sep 2023 13:51:07 +0200 Subject: [PATCH] HHH-17167 Add test for issue --- ...est.java => RowIdUpdateAndDeleteTest.java} | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) rename hibernate-core/src/test/java/org/hibernate/orm/test/rowid/{RowIdUpdateTest.java => RowIdUpdateAndDeleteTest.java} (76%) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdUpdateTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdUpdateAndDeleteTest.java similarity index 76% rename from hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdUpdateTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdUpdateAndDeleteTest.java index e472badee5..20cee8e185 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdUpdateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdUpdateAndDeleteTest.java @@ -30,15 +30,21 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Marco Belladelli */ -@DomainModel( annotatedClasses = { RowIdUpdateTest.SimpleEntity.class, RowIdUpdateTest.ParentEntity.class } ) +@DomainModel( annotatedClasses = { + RowIdUpdateAndDeleteTest.SimpleEntity.class, + RowIdUpdateAndDeleteTest.ParentEntity.class +} ) @SessionFactory( useCollectingStatementInspector = true ) @Jira( "https://hibernate.atlassian.net/browse/HHH-17045" ) -public class RowIdUpdateTest { +@Jira( "https://hibernate.atlassian.net/browse/HHH-17167" ) +public class RowIdUpdateAndDeleteTest { @BeforeAll public void setUp(SessionFactoryScope scope) { scope.inTransaction( session -> { session.persist( new SimpleEntity( 1L, "initial_status" ) ); session.persist( new ParentEntity( 2L, new SimpleEntity( 2L, "initial_status" ) ) ); + session.persist( new SimpleEntity( 11L, "to_delete" ) ); + session.persist( new ParentEntity( 12L, new SimpleEntity( 12L, "to_delete" ) ) ); } ); } @@ -68,6 +74,22 @@ public class RowIdUpdateTest { ).isEqualTo( "new_status" ) ); } + @Test + public void testSimpleDeleteSameTransaction(SessionFactoryScope scope) { + final SQLStatementInspector inspector = scope.getCollectingStatementInspector(); + inspector.clear(); + scope.inTransaction( session -> { + final SimpleEntity simpleEntity = new SimpleEntity( 13L, "to_delete" ); + session.persist( simpleEntity ); + session.flush(); + session.remove( simpleEntity ); + inspector.clear(); + } ); + // the update should have used the primary key, as the row-id value is not available + checkUpdateQuery( inspector, true ); + scope.inTransaction( session -> assertThat( session.find( SimpleEntity.class, 13L ) ).isNull() ); + } + @Test public void testRelatedUpdateSameTransaction(SessionFactoryScope scope) { final SQLStatementInspector inspector = scope.getCollectingStatementInspector(); @@ -107,6 +129,19 @@ public class RowIdUpdateTest { ).isEqualTo( "new_status" ) ); } + @Test + public void testSimpleDeleteDifferentTransaction(SessionFactoryScope scope) { + final SQLStatementInspector inspector = scope.getCollectingStatementInspector(); + scope.inTransaction( session -> { + final SimpleEntity simpleEntity = session.find( SimpleEntity.class, 11L ); + session.remove( simpleEntity ); + inspector.clear(); + } ); + final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect(); + checkUpdateQuery( inspector, dialect.rowId( "" ) == null ); + scope.inTransaction( session -> assertThat( session.find( SimpleEntity.class, 11L ) ).isNull() ); + } + @Test public void testRelatedUpdateRelatedDifferentTransaction(SessionFactoryScope scope) { final SQLStatementInspector inspector = scope.getCollectingStatementInspector();