HHH-16821 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-06-23 12:04:44 +02:00 committed by Andrea Boriero
parent 44439cad95
commit 2e4211e8eb
2 changed files with 26 additions and 22 deletions

View File

@ -635,31 +635,35 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
for ( int i = 0; i < size; i++ ) { for ( int i = 0; i < size; i++ ) {
final AttributeMapping attributeMapping = attributeMappings.get( i ); final AttributeMapping attributeMapping = attributeMappings.get( i );
final Object attributeValue = values[ i ]; if ( !attributeMapping.isPluralAttributeMapping() ) {
span += attributeMapping.breakDownJdbcValues( final Object attributeValue = values[i];
attributeValue, span += attributeMapping.breakDownJdbcValues(
offset + span, attributeValue,
x, offset + span,
y, x,
valueConsumer, y,
session valueConsumer,
); session
);
}
} }
} }
else { else {
for ( int i = 0; i < size; i++ ) { for ( int i = 0; i < size; i++ ) {
final AttributeMapping attributeMapping = attributeMappings.get( i ); final AttributeMapping attributeMapping = attributeMappings.get( i );
final Object attributeValue = domainValue == null if ( !attributeMapping.isPluralAttributeMapping() ) {
? null final Object attributeValue = domainValue == null
: attributeMapping.getPropertyAccess().getGetter().get( domainValue ); ? null
span += attributeMapping.breakDownJdbcValues( : attributeMapping.getPropertyAccess().getGetter().get( domainValue );
attributeValue, span += attributeMapping.breakDownJdbcValues(
offset + span, attributeValue,
x, offset + span,
y, x,
valueConsumer, y,
session valueConsumer,
); session
);
}
} }
} }
return span; return span;

View File

@ -165,7 +165,7 @@ public class DeleteCoordinator extends AbstractMutationCoordinator {
for ( int attributeIndex = 0; attributeIndex < versionability.length; attributeIndex++ ) { for ( int attributeIndex = 0; attributeIndex < versionability.length; attributeIndex++ ) {
final AttributeMapping attribute; final AttributeMapping attribute;
// only makes sense to lock on singular attributes which are not excluded from optimistic locking // only makes sense to lock on singular attributes which are not excluded from optimistic locking
if ( versionability[attributeIndex] && ( attribute = persister.getAttributeMapping( attributeIndex ) ) instanceof SingularAttributeMapping ) { if ( versionability[attributeIndex] && !( attribute = persister.getAttributeMapping( attributeIndex ) ).isPluralAttributeMapping() ) {
final Object loadedValue = loadedState[attributeIndex]; final Object loadedValue = loadedState[attributeIndex];
if ( loadedValue != null ) { if ( loadedValue != null ) {
final String mutationTableName = persister.getAttributeMutationTableName( attributeIndex ); final String mutationTableName = persister.getAttributeMutationTableName( attributeIndex );
@ -424,7 +424,7 @@ public class DeleteCoordinator extends AbstractMutationCoordinator {
for ( int attributeIndex = 0; attributeIndex < versionability.length; attributeIndex++ ) { for ( int attributeIndex = 0; attributeIndex < versionability.length; attributeIndex++ ) {
final AttributeMapping attribute; final AttributeMapping attribute;
// only makes sense to lock on singular attributes which are not excluded from optimistic locking // only makes sense to lock on singular attributes which are not excluded from optimistic locking
if ( versionability[attributeIndex] && ( attribute = persister.getAttributeMapping( attributeIndex ) ) instanceof SingularAttributeMapping ) { if ( versionability[attributeIndex] && !( attribute = persister.getAttributeMapping( attributeIndex ) ).isPluralAttributeMapping() ) {
breakDownJdbcValues( mutationGroupBuilder, session, attribute, loadedState[attributeIndex] ); breakDownJdbcValues( mutationGroupBuilder, session, attribute, loadedState[attributeIndex] );
} }
} }