Skip to content

Commit 3da12ca

Browse files
mbelladebeikov
authored andcommitted
HHH-17167 Add test for issue
1 parent 3eb324f commit 3da12ca

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdUpdateTest.java renamed to hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdUpdateAndDeleteTest.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@
3030
/**
3131
* @author Marco Belladelli
3232
*/
33-
@DomainModel( annotatedClasses = { RowIdUpdateTest.SimpleEntity.class, RowIdUpdateTest.ParentEntity.class } )
33+
@DomainModel( annotatedClasses = {
34+
RowIdUpdateAndDeleteTest.SimpleEntity.class,
35+
RowIdUpdateAndDeleteTest.ParentEntity.class
36+
} )
3437
@SessionFactory( useCollectingStatementInspector = true )
3538
@Jira( "https://hibernate.atlassian.net/browse/HHH-17045" )
36-
public class RowIdUpdateTest {
39+
@Jira( "https://hibernate.atlassian.net/browse/HHH-17167" )
40+
public class RowIdUpdateAndDeleteTest {
3741
@BeforeAll
3842
public void setUp(SessionFactoryScope scope) {
3943
scope.inTransaction( session -> {
4044
session.persist( new SimpleEntity( 1L, "initial_status" ) );
4145
session.persist( new ParentEntity( 2L, new SimpleEntity( 2L, "initial_status" ) ) );
46+
session.persist( new SimpleEntity( 11L, "to_delete" ) );
47+
session.persist( new ParentEntity( 12L, new SimpleEntity( 12L, "to_delete" ) ) );
4248
} );
4349
}
4450

@@ -68,6 +74,22 @@ public void testSimpleUpdateSameTransaction(SessionFactoryScope scope) {
6874
).isEqualTo( "new_status" ) );
6975
}
7076

77+
@Test
78+
public void testSimpleDeleteSameTransaction(SessionFactoryScope scope) {
79+
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
80+
inspector.clear();
81+
scope.inTransaction( session -> {
82+
final SimpleEntity simpleEntity = new SimpleEntity( 13L, "to_delete" );
83+
session.persist( simpleEntity );
84+
session.flush();
85+
session.remove( simpleEntity );
86+
inspector.clear();
87+
} );
88+
// the update should have used the primary key, as the row-id value is not available
89+
checkUpdateQuery( inspector, true );
90+
scope.inTransaction( session -> assertThat( session.find( SimpleEntity.class, 13L ) ).isNull() );
91+
}
92+
7193
@Test
7294
public void testRelatedUpdateSameTransaction(SessionFactoryScope scope) {
7395
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
@@ -107,6 +129,19 @@ public void testSimpleUpdateDifferentTransaction(SessionFactoryScope scope) {
107129
).isEqualTo( "new_status" ) );
108130
}
109131

132+
@Test
133+
public void testSimpleDeleteDifferentTransaction(SessionFactoryScope scope) {
134+
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
135+
scope.inTransaction( session -> {
136+
final SimpleEntity simpleEntity = session.find( SimpleEntity.class, 11L );
137+
session.remove( simpleEntity );
138+
inspector.clear();
139+
} );
140+
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
141+
checkUpdateQuery( inspector, dialect.rowId( "" ) == null );
142+
scope.inTransaction( session -> assertThat( session.find( SimpleEntity.class, 11L ) ).isNull() );
143+
}
144+
110145
@Test
111146
public void testRelatedUpdateRelatedDifferentTransaction(SessionFactoryScope scope) {
112147
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();

0 commit comments

Comments
 (0)