HHH-17755 fix inferral of @IdClass column mapping from @MapsId

This commit is contained in:
Gavin King 2024-02-20 13:28:44 +01:00 committed by Marco Belladelli
parent 22b1d606c5
commit e51d03c0ba
1 changed files with 14 additions and 3 deletions

View File

@ -1011,7 +1011,10 @@ public class PropertyBinder {
final boolean isComposite;
final boolean isOverridden;
final AnnotatedColumns actualColumns;
if ( propertyBinder.isId() || propertyHolder.isOrWithinEmbeddedId() || propertyHolder.isInIdClass() ) {
if ( isIdentifierMapper
|| propertyBinder.isId()
|| propertyHolder.isOrWithinEmbeddedId()
|| propertyHolder.isInIdClass() ) {
// the associated entity could be using an @IdClass making the overridden property a component
final PropertyData overridingProperty = getPropertyOverriddenByMapperOrMapsId(
propertyBinder.isId(),
@ -1021,8 +1024,7 @@ public class PropertyBinder {
);
if ( overridingProperty != null ) {
isOverridden = true;
final InheritanceState state = inheritanceStatePerClass.get( overridingProperty.getClassOrElement() );
isComposite = state != null ? state.hasIdClassOrEmbeddedId() : isEmbedded( property, returnedClass );
isComposite = isComposite( inheritanceStatePerClass, property, returnedClass, overridingProperty );
//Get the new column
actualColumns = columnsBuilder.overrideColumnFromMapperOrMapsIdProperty( propertyBinder.isId() );
}
@ -1102,6 +1104,15 @@ public class PropertyBinder {
return actualColumns;
}
private static boolean isComposite(
Map<XClass, InheritanceState> inheritanceStatePerClass,
XProperty property,
XClass returnedClass,
PropertyData overridingProperty) {
final InheritanceState state = inheritanceStatePerClass.get( overridingProperty.getClassOrElement() );
return state != null ? state.hasIdClassOrEmbeddedId() : isEmbedded( property, returnedClass );
}
private static void handleGeneratorsForOverriddenId(
PropertyHolder propertyHolder,
Map<String, IdentifierGeneratorDefinition> classGenerators,