1818import org .hibernate .engine .jdbc .mutation .internal .PreparedStatementGroupSingleTable ;
1919import org .hibernate .engine .jdbc .mutation .spi .Binding ;
2020import org .hibernate .engine .jdbc .mutation .spi .BindingGroup ;
21+ import org .hibernate .engine .jdbc .spi .JdbcServices ;
2122import org .hibernate .engine .spi .SharedSessionContractImplementor ;
23+ import org .hibernate .jdbc .Expectation ;
2224import org .hibernate .persister .entity .mutation .EntityMutationTarget ;
2325import org .hibernate .persister .entity .mutation .EntityTableMapping ;
2426import org .hibernate .persister .entity .mutation .UpdateValuesAnalysis ;
@@ -44,6 +46,8 @@ public class DeleteOrUpsertOperation implements SelfExecutingUpdateOperation {
4446
4547 private final OptionalTableUpdate optionalTableUpdate ;
4648
49+ private final Expectation expectation = new Expectation .RowCount ();
50+
4751 public DeleteOrUpsertOperation (
4852 EntityMutationTarget mutationTarget ,
4953 EntityTableMapping tableMapping ,
@@ -125,7 +129,8 @@ private void performDelete(JdbcValueBindings jdbcValueBindings, SharedSessionCon
125129
126130 try {
127131 final PreparedStatement upsertDeleteStatement = statementDetails .resolveStatement ();
128- session .getJdbcServices ().getSqlStatementLogger ().logStatement ( statementDetails .getSqlString () );
132+ final JdbcServices jdbcServices = session .getJdbcServices ();
133+ jdbcServices .getSqlStatementLogger ().logStatement ( statementDetails .getSqlString () );
129134
130135 bindDeleteKeyValues (
131136 jdbcValueBindings ,
@@ -137,6 +142,16 @@ private void performDelete(JdbcValueBindings jdbcValueBindings, SharedSessionCon
137142 final int rowCount = session .getJdbcCoordinator ().getResultSetReturn ()
138143 .executeUpdate ( upsertDeleteStatement , statementDetails .getSqlString () );
139144 MODEL_MUTATION_LOGGER .tracef ( "`%s` rows upsert-deleted from `%s`" , rowCount , tableMapping .getTableName () );
145+ try {
146+ expectation .verifyOutcome ( rowCount , upsertDeleteStatement , -1 , statementDetails .getSqlString () );
147+ }
148+ catch (SQLException e ) {
149+ throw jdbcServices .getSqlExceptionHelper ().convert (
150+ e ,
151+ "Unable to verify outcome for upsert delete" ,
152+ statementDetails .getSqlString ()
153+ );
154+ }
140155 }
141156 finally {
142157 statementDetails .releaseStatement ( session );
@@ -204,14 +219,24 @@ private void performUpsert(JdbcValueBindings jdbcValueBindings, SharedSessionCon
204219
205220 try {
206221 final PreparedStatement updateStatement = statementDetails .resolveStatement ();
207- session .getJdbcServices (). getSqlStatementLogger (). logStatement ( statementDetails . getSqlString () );
208-
222+ final JdbcServices jdbcServices = session .getJdbcServices ();
223+ jdbcServices . getSqlStatementLogger (). logStatement ( statementDetails . getSqlString () );
209224 jdbcValueBindings .beforeStatement ( statementDetails );
210225
211226 final int rowCount = session .getJdbcCoordinator ().getResultSetReturn ()
212227 .executeUpdate ( updateStatement , statementDetails .getSqlString () );
213228
214229 MODEL_MUTATION_LOGGER .tracef ( "`%s` rows upserted into `%s`" , rowCount , tableMapping .getTableName () );
230+ try {
231+ expectation .verifyOutcome ( rowCount , updateStatement , -1 , statementDetails .getSqlString () );
232+ }
233+ catch (SQLException e ) {
234+ throw jdbcServices .getSqlExceptionHelper ().convert (
235+ e ,
236+ "Unable to verify outcome for upsert" ,
237+ statementDetails .getSqlString ()
238+ );
239+ }
215240 }
216241 finally {
217242 statementDetails .releaseStatement ( session );
0 commit comments