1616import org .hibernate .engine .jdbc .mutation .spi .Binding ;
1717import org .hibernate .engine .jdbc .spi .JdbcServices ;
1818import org .hibernate .engine .spi .SharedSessionContractImplementor ;
19+ import org .hibernate .jdbc .Expectation ;
1920import org .hibernate .persister .entity .mutation .EntityMutationTarget ;
2021import org .hibernate .persister .entity .mutation .EntityTableMapping ;
2122import org .hibernate .persister .entity .mutation .UpdateValuesAnalysis ;
@@ -40,6 +41,8 @@ public class DeleteOrUpsertOperation implements SelfExecutingUpdateOperation {
4041
4142 private final OptionalTableUpdate optionalTableUpdate ;
4243
44+ private final Expectation expectation = new Expectation .RowCount ();
45+
4346 public DeleteOrUpsertOperation (
4447 EntityMutationTarget mutationTarget ,
4548 EntityTableMapping tableMapping ,
@@ -123,6 +126,16 @@ private void performDelete(JdbcValueBindings jdbcValueBindings, SharedSessionCon
123126 final int rowCount = session .getJdbcCoordinator ().getResultSetReturn ()
124127 .executeUpdate ( upsertDeleteStatement , statementDetails .getSqlString () );
125128 MODEL_MUTATION_LOGGER .tracef ( "`%s` rows upsert-deleted from `%s`" , rowCount , tableMapping .getTableName () );
129+ try {
130+ expectation .verifyOutcome ( rowCount , upsertDeleteStatement , -1 , statementDetails .getSqlString () );
131+ }
132+ catch (SQLException e ) {
133+ throw jdbcServices .getSqlExceptionHelper ().convert (
134+ e ,
135+ "Unable to verify outcome for upsert delete" ,
136+ statementDetails .getSqlString ()
137+ );
138+ }
126139 }
127140 finally {
128141 statementDetails .releaseStatement ( session );
@@ -182,12 +195,23 @@ private void performUpsert(JdbcValueBindings jdbcValueBindings, SharedSessionCon
182195 final var statementDetails = statementGroup .resolvePreparedStatementDetails ( tableMapping .getTableName () );
183196 try {
184197 final PreparedStatement updateStatement = statementDetails .resolveStatement ();
185- session .getJdbcServices ().getSqlStatementLogger ().logStatement ( statementDetails .getSqlString () );
198+ final JdbcServices jdbcServices = session .getJdbcServices ();
199+ jdbcServices .getSqlStatementLogger ().logStatement ( statementDetails .getSqlString () );
186200 jdbcValueBindings .beforeStatement ( statementDetails );
187201 final int rowCount =
188202 session .getJdbcCoordinator ().getResultSetReturn ()
189203 .executeUpdate ( updateStatement , statementDetails .getSqlString () );
190204 MODEL_MUTATION_LOGGER .tracef ( "`%s` rows upserted into `%s`" , rowCount , tableMapping .getTableName () );
205+ try {
206+ expectation .verifyOutcome ( rowCount , updateStatement , -1 , statementDetails .getSqlString () );
207+ }
208+ catch (SQLException e ) {
209+ throw jdbcServices .getSqlExceptionHelper ().convert (
210+ e ,
211+ "Unable to verify outcome for upsert" ,
212+ statementDetails .getSqlString ()
213+ );
214+ }
191215 }
192216 finally {
193217 statementDetails .releaseStatement ( session );
0 commit comments