|
30 | 30 | /**
|
31 | 31 | * @author Marco Belladelli
|
32 | 32 | */
|
33 |
| -@DomainModel( annotatedClasses = { RowIdUpdateTest.SimpleEntity.class, RowIdUpdateTest.ParentEntity.class } ) |
| 33 | +@DomainModel( annotatedClasses = { |
| 34 | + RowIdUpdateAndDeleteTest.SimpleEntity.class, |
| 35 | + RowIdUpdateAndDeleteTest.ParentEntity.class |
| 36 | +} ) |
34 | 37 | @SessionFactory( useCollectingStatementInspector = true )
|
35 | 38 | @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 { |
37 | 41 | @BeforeAll
|
38 | 42 | public void setUp(SessionFactoryScope scope) {
|
39 | 43 | scope.inTransaction( session -> {
|
40 | 44 | session.persist( new SimpleEntity( 1L, "initial_status" ) );
|
41 | 45 | 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" ) ) ); |
42 | 48 | } );
|
43 | 49 | }
|
44 | 50 |
|
@@ -68,6 +74,22 @@ public void testSimpleUpdateSameTransaction(SessionFactoryScope scope) {
|
68 | 74 | ).isEqualTo( "new_status" ) );
|
69 | 75 | }
|
70 | 76 |
|
| 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 | + |
71 | 93 | @Test
|
72 | 94 | public void testRelatedUpdateSameTransaction(SessionFactoryScope scope) {
|
73 | 95 | final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
|
@@ -107,6 +129,19 @@ public void testSimpleUpdateDifferentTransaction(SessionFactoryScope scope) {
|
107 | 129 | ).isEqualTo( "new_status" ) );
|
108 | 130 | }
|
109 | 131 |
|
| 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 | + |
110 | 145 | @Test
|
111 | 146 | public void testRelatedUpdateRelatedDifferentTransaction(SessionFactoryScope scope) {
|
112 | 147 | final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
|
|
0 commit comments