diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/DeleteCoordinator.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/DeleteCoordinator.java index 4994acb037..79189ab228 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/DeleteCoordinator.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/mutation/DeleteCoordinator.java @@ -22,7 +22,6 @@ import org.hibernate.metamodel.mapping.AttributeMappingsList; import org.hibernate.metamodel.mapping.EntityRowIdMapping; import org.hibernate.metamodel.mapping.EntityVersionMapping; import org.hibernate.metamodel.mapping.SelectableMapping; -import org.hibernate.metamodel.mapping.SingularAttributeMapping; import org.hibernate.persister.entity.AbstractEntityPersister; import org.hibernate.sql.model.MutationOperationGroup; import org.hibernate.sql.model.MutationType; @@ -438,11 +437,17 @@ public class DeleteCoordinator extends AbstractMutationCoordinator { if ( tableMutationBuilder != null && tableMutationBuilder.getOptimisticLockBindings() != null ) { attribute.breakDownJdbcValues( loadedValue, - tableMutationBuilder.getOptimisticLockBindings(), + (valueIndex, value, jdbcValueMapping) -> { + if ( value != null && !tableMutationBuilder.getKeyRestrictionBindings().contains( value ) ) { + tableMutationBuilder.getOptimisticLockBindings().consume( valueIndex, value, jdbcValueMapping ); + } + } + , session ); } // else there is no actual delete statement for that table, // generally indicates we have an on-delete=cascade situation } + } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/model/ast/builder/RestrictedTableMutationBuilder.java b/hibernate-core/src/main/java/org/hibernate/sql/model/ast/builder/RestrictedTableMutationBuilder.java index 7e5243010a..c5470cb6be 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/model/ast/builder/RestrictedTableMutationBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/model/ast/builder/RestrictedTableMutationBuilder.java @@ -7,7 +7,6 @@ package org.hibernate.sql.model.ast.builder; import org.hibernate.metamodel.mapping.JdbcMapping; -import org.hibernate.metamodel.mapping.SelectableConsumer; import org.hibernate.metamodel.mapping.SelectableMapping; import org.hibernate.metamodel.mapping.SelectableMappings; import org.hibernate.sql.model.MutationOperation;