Allow ast navigation embedded > to-one

This commit is contained in:
Fabio Massimo Ercoli 2021-10-26 18:45:21 +02:00
parent 4e216a121c
commit de0dffe105
2 changed files with 21 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.internal.AbstractDomainPath;
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
import org.hibernate.metamodel.mapping.ordering.TranslationContext;
import org.hibernate.query.NavigablePath;
@ -64,9 +65,26 @@ public class DomainPathContinuation extends AbstractDomainPath {
subPart
);
}
if ( referencedModelPart instanceof ToOneAttributeMapping ) {
ToOneAttributeMapping toOneAttribute = (ToOneAttributeMapping) referencedModelPart;
if ( name.equals( toOneAttribute.getTargetKeyPropertyName() ) ) {
final ModelPart subPart = toOneAttribute.findSubPart( name );
if ( subPart == null ) {
throw new PathResolutionException(
"Could not resolve path token : " + referencedModelPart + " -> " + name
);
}
return new DomainPathContinuation(
navigablePath.append( name ),
this,
subPart
);
}
}
throw new PathResolutionException(
"Domain path of type `" + referencedModelPart.getPartMappingType() +
"Domain path of type `" + referencedModelPart.getPartMappingType() +
"` -> `" + name + "`"
);
}

View File

@ -11,6 +11,7 @@ import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.internal.AbstractDomainPath;
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
import org.hibernate.metamodel.mapping.ordering.TranslationContext;
import org.hibernate.query.NavigablePath;
@ -55,7 +56,7 @@ public class PluralAttributePath extends AbstractDomainPath {
if ( subPart instanceof CollectionPart ) {
return new CollectionPartPath( this, (CollectionPart) subPart );
}
else if ( !( subPart instanceof EmbeddableValuedModelPart ) ) {
else if ( !( subPart instanceof EmbeddableValuedModelPart || subPart instanceof ToOneAttributeMapping ) ) {
final CollectionPartPath elementPath = new CollectionPartPath(
this,
pluralAttributeMapping.getElementDescriptor()