HHH-16810 Fail to delete entity with a composite id using an @IdClass with one of its fields mapped from the id of a @ManyToOne association

This commit is contained in:
Andrea Boriero 2023-07-04 15:23:52 +02:00 committed by Andrea Boriero
parent b9e2105639
commit 814923dd46
2 changed files with 7 additions and 3 deletions

View File

@ -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
}
}

View File

@ -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;