Skip to content

Commit 3b5041a

Browse files
dreab8mbelladebeikov
committed
HHH-20287 DataException ( Parameter is not set) when updating only the version of an Entity with a PartitionKey
Co-authored-by: Marco Belladelli <marcobladel@gmail.com> Co-authored-by: Christian Beikov <christian.beikov@gmail.com>
1 parent 46d8220 commit 3b5041a

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/UpdateCoordinatorStandard.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Locale;
1212
import java.util.function.Supplier;
1313

14+
import org.checkerframework.checker.nullness.qual.Nullable;
1415
import org.hibernate.AssertionFailure;
1516
import org.hibernate.HibernateException;
1617
import org.hibernate.Internal;
@@ -150,7 +151,14 @@ public void forceVersionIncrement(
150151
if ( versionUpdateGroup == null ) {
151152
throw new HibernateException( "Cannot force version increment relative to sub-type; use the root type" );
152153
}
153-
doVersionUpdate( null, id, nextVersion, currentVersion, null, session );
154+
doVersionUpdate( null, id, nextVersion, currentVersion, getLoadedState( id, session ), session );
155+
}
156+
157+
private Object @Nullable [] getLoadedState(Object id, SharedSessionContractImplementor session) {
158+
return entityPersister.hasPartitionedSelectionMapping()
159+
? session.getPersistenceContextInternal()
160+
.getEntityHolder( session.generateEntityKey( id, entityPersister ) ).getEntityEntry().getLoadedState()
161+
: null;
154162
}
155163

156164
@Override
@@ -163,7 +171,7 @@ public void forceVersionIncrement(
163171
if ( versionUpdateGroup == null ) {
164172
throw new HibernateException( "Cannot force version increment relative to sub-type; use the root type" );
165173
}
166-
doVersionUpdate( null, id, nextVersion, currentVersion, batching, null, session );
174+
doVersionUpdate( null, id, nextVersion, currentVersion, batching, getLoadedState( id, session ), session );
167175
}
168176

169177
@Override
@@ -183,6 +191,7 @@ public GeneratedValues update(
183191
entity,
184192
id,
185193
values,
194+
incomingOldValues,
186195
oldVersion,
187196
incomingDirtyAttributeIndexes,
188197
session,
@@ -403,6 +412,7 @@ protected Supplier<GeneratedValues> handlePotentialImplicitForcedVersionIncremen
403412
Object entity,
404413
Object id,
405414
Object[] values,
415+
Object[] oldValues,
406416
Object oldVersion,
407417
int[] incomingDirtyAttributeIndexes,
408418
SharedSessionContractImplementor session,
@@ -441,7 +451,14 @@ else if ( incomingDirtyAttributeIndexes.length == 0 && oldVersion != null ) {
441451
if ( isSimpleVersionUpdate ) {
442452
// we have just the version being updated - use the special handling
443453
assert newVersion != null;
444-
final GeneratedValues generatedValues = doVersionUpdate( entity, id, newVersion, oldVersion, values, session );
454+
final GeneratedValues generatedValues = doVersionUpdate(
455+
entity,
456+
id,
457+
newVersion,
458+
oldVersion,
459+
oldValues == null ? values : oldValues,
460+
session
461+
);
445462
return () -> generatedValues;
446463
}
447464
else {
@@ -475,15 +492,15 @@ protected GeneratedValues doVersionUpdate(
475492
Object id,
476493
Object version,
477494
Object oldVersion,
478-
Object[] laodedState,
495+
Object[] loadedState,
479496
SharedSessionContractImplementor session) {
480497
return doVersionUpdate(
481498
entity,
482499
id,
483500
version,
484501
oldVersion,
485502
true,
486-
laodedState,
503+
loadedState,
487504
session
488505
);
489506
}
@@ -512,12 +529,7 @@ protected GeneratedValues doVersionUpdate(
512529
ParameterUsage.SET
513530
);
514531

515-
if ( loadedState != null && entityPersister.hasPartitionedSelectionMapping() ) {
516-
bindPartitionColumnValueBindings(
517-
loadedState,
518-
session,
519-
mutationExecutor.getJdbcValueBindings() );
520-
}
532+
bindPartitionColumnValueBindings( loadedState, session, mutationExecutor.getJdbcValueBindings() );
521533

522534
// restrict the key
523535
mutatingTableDetails.getKeyMapping().breakDownKeyJdbcValues(

0 commit comments

Comments
 (0)