HHH-16209 Identically-named association in entity root and embeddable leads to mixup during association loading

This commit is contained in:
Andrea Boriero 2023-02-27 15:46:23 +01:00
parent 5e82db1caa
commit f728b380a3
2 changed files with 33 additions and 1 deletions

View File

@ -1065,7 +1065,15 @@ public class ToOneAttributeMapping
}
return false;
}
return parentNavigablePath.isSuffix( bidirectionalAttributePath );
NavigablePath navigablePath = parentNavigablePath.trimSuffix( bidirectionalAttributePath );
if ( navigablePath != null ) {
if ( navigablePath.getLocalName().equals( EntityIdentifierMapping.ROLE_LOCAL_NAME ) ) {
navigablePath = navigablePath.getParent();
}
return creationState.resolveModelPart( navigablePath ).getPartMappingType() == entityMappingType;
}
return false;
}
private boolean isParentEmbeddedCollectionPart(DomainResultCreationState creationState, NavigablePath parentNavigablePath) {

View File

@ -205,6 +205,30 @@ public class NavigablePath implements DotIdentifierSequence, Serializable {
return getParent() != null && getParent().isSuffix( dotIdentifierSequence.getParent() );
}
/**
*
* Removes the suffix part from the NavigablePath,
* when the NavigablePath does not contain the suffix it returns null;
*
* @param suffix the part to remove from the NavigablePath
*
* @return the NavigablePath stripped of the suffix part
* or null if the NavigablePath does not contain the suffix.
*
*/
public NavigablePath trimSuffix(DotIdentifierSequence suffix) {
if ( suffix == null ) {
return this;
}
if ( !getLocalName().equals( suffix.getLocalName() ) ) {
return null;
}
if ( getParent() != null ) {
return getParent().trimSuffix( suffix.getParent() );
}
return null;
}
/**
* Determine whether this path is part of the given path's parent
*/