Defer the extraction of the sub part

When the foreign key is set to the to-one attribute, this is necessary to have an entity identity mapping using the foreign key SQL attributes
This commit is contained in:
Fabio Massimo Ercoli 2021-10-27 18:08:30 +02:00
parent de0dffe105
commit fdcb07420f
2 changed files with 16 additions and 2 deletions

View File

@ -148,12 +148,24 @@ public abstract class AbstractDomainPath implements DomainPath {
); );
} }
else if ( referenceModelPart instanceof EntityValuedModelPart ) { else if ( referenceModelPart instanceof EntityValuedModelPart ) {
final ModelPart subPart; ModelPart subPart;
if ( ELEMENT_TOKEN.equals( modelPartName ) ) { if ( ELEMENT_TOKEN.equals( modelPartName ) ) {
subPart = ( (EntityValuedModelPart) referenceModelPart ).getEntityMappingType().getIdentifierMapping(); subPart = ( (EntityValuedModelPart) referenceModelPart ).getEntityMappingType().getIdentifierMapping();
} }
else { else {
subPart = ( (EntityValuedModelPart) referenceModelPart ).findSubPart( modelPartName ); subPart = ( (EntityValuedModelPart) referenceModelPart ).findSubPart( modelPartName );
if ( subPart == null && referenceModelPart instanceof ToOneAttributeMapping ) {
// this is the case of sort by to-one attribute inside an embedded item,
// at this stage the foreign key descriptor should have been set on the attribute mapping,
// so we can generate a sub part valid for the order-by generation
ToOneAttributeMapping toOneAttribute = (ToOneAttributeMapping) referenceModelPart;
String foreignKeyModelPart = toOneAttribute.getAttributeName() + "."
+ toOneAttribute.getTargetKeyPropertyName();
if ( modelPartName.equals( foreignKeyModelPart ) ) {
subPart = toOneAttribute.findSubPart( toOneAttribute.getTargetKeyPropertyName() );
}
}
} }
apply( apply(
subPart, subPart,

View File

@ -78,7 +78,9 @@ public class DomainPathContinuation extends AbstractDomainPath {
return new DomainPathContinuation( return new DomainPathContinuation(
navigablePath.append( name ), navigablePath.append( name ),
this, this,
subPart // unfortunately at this stage the foreign key descriptor could not be set
// on the attribute mapping yet, so we need to defer the sub part extraction later
referencedModelPart
); );
} }
} }