99import java .util .Locale ;
1010import java .util .function .Supplier ;
1111
12+ import org .checkerframework .checker .nullness .qual .Nullable ;
1213import org .hibernate .HibernateException ;
1314import org .hibernate .Internal ;
1415import org .hibernate .StaleObjectStateException ;
@@ -140,7 +141,14 @@ public void forceVersionIncrement(
140141 if ( versionUpdateGroup == null ) {
141142 throw new HibernateException ( "Cannot force version increment relative to subtype; use the root type" );
142143 }
143- doVersionUpdate ( null , id , nextVersion , currentVersion , null , session );
144+ doVersionUpdate ( null , id , nextVersion , currentVersion , getLoadedState ( id , session ), session );
145+ }
146+
147+ private Object @ Nullable [] getLoadedState (Object id , SharedSessionContractImplementor session ) {
148+ return entityPersister .hasPartitionedSelectionMapping ()
149+ ? session .getPersistenceContextInternal ()
150+ .getEntityHolder ( session .generateEntityKey ( id , entityPersister ) ).getEntityEntry ().getLoadedState ()
151+ : null ;
144152 }
145153
146154 @ Override
@@ -153,7 +161,7 @@ public void forceVersionIncrement(
153161 if ( versionUpdateGroup == null ) {
154162 throw new HibernateException ( "Cannot force version increment relative to subtype; use the root type" );
155163 }
156- doVersionUpdate ( null , id , nextVersion , currentVersion , batching , null , session );
164+ doVersionUpdate ( null , id , nextVersion , currentVersion , batching , getLoadedState ( id , session ) , session );
157165 }
158166
159167 @ Override
@@ -174,6 +182,7 @@ public GeneratedValues update(
174182 entity ,
175183 id ,
176184 values ,
185+ incomingOldValues ,
177186 oldVersion ,
178187 incomingDirtyAttributeIndexes ,
179188 session ,
@@ -386,6 +395,7 @@ protected Supplier<GeneratedValues> handlePotentialImplicitForcedVersionIncremen
386395 Object entity ,
387396 Object id ,
388397 Object [] values ,
398+ Object [] oldValues ,
389399 Object oldVersion ,
390400 int [] incomingDirtyAttributeIndexes ,
391401 SharedSessionContractImplementor session ,
@@ -436,7 +446,14 @@ else if ( incomingDirtyAttributeIndexes != null ) {
436446
437447 // we have just the version being updated - use the special handling
438448 assert newVersion != null ;
439- final var generatedValues = doVersionUpdate ( entity , id , newVersion , oldVersion , values , session );
449+ final var generatedValues = doVersionUpdate (
450+ entity ,
451+ id ,
452+ newVersion ,
453+ oldVersion ,
454+ oldValues == null ? values : oldValues ,
455+ session
456+ );
440457 return () -> generatedValues ;
441458 }
442459
@@ -472,15 +489,15 @@ protected GeneratedValues doVersionUpdate(
472489 Object id ,
473490 Object version ,
474491 Object oldVersion ,
475- Object [] laodedState ,
492+ Object [] loadedState ,
476493 SharedSessionContractImplementor session ) {
477494 return doVersionUpdate (
478495 entity ,
479496 id ,
480497 version ,
481498 oldVersion ,
482499 true ,
483- laodedState ,
500+ loadedState ,
484501 session
485502 );
486503 }
@@ -511,12 +528,7 @@ protected GeneratedValues doVersionUpdate(
511528 ParameterUsage .SET
512529 );
513530
514- if ( loadedState != null && entityPersister .hasPartitionedSelectionMapping () ) {
515- bindPartitionColumnValueBindings (
516- loadedState ,
517- session ,
518- mutationExecutor .getJdbcValueBindings () );
519- }
531+ bindPartitionColumnValueBindings ( loadedState , session , mutationExecutor .getJdbcValueBindings () );
520532
521533 // restrict the key
522534 mutatingTableDetails .getKeyMapping ().breakDownKeyJdbcValues (
0 commit comments