Skip to content

Commit

Permalink
HHH-17280 Allow partial embedded fk resolution on parent
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel authored and beikov committed Nov 27, 2023
1 parent 7245ab7 commit d25fb20
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
import org.hibernate.internal.util.IndexedConsumer;
import org.hibernate.internal.util.MutableInteger;
import org.hibernate.metamodel.mapping.AssociationKey;
import org.hibernate.metamodel.mapping.AttributeMappingsList;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping;
import org.hibernate.metamodel.mapping.SelectableConsumer;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.SelectableMappings;
Expand Down Expand Up @@ -196,18 +196,16 @@ public boolean isKeyPart(ValuedModelPart modelPart) {
if ( this == modelPart || keyPart == modelPart ) {
return true;
}
else if ( keyPart instanceof NonAggregatedIdentifierMapping ) {
final AttributeMappingsList attributeMappings = ( (NonAggregatedIdentifierMapping) keyPart ).getVirtualIdEmbeddable()
.getAttributeMappings();
for ( int i = 0; i < attributeMappings.size(); i++ ) {
if ( modelPart == attributeMappings.get( i ) ) {
else {
AttributeMapping attributeMapping = modelPart.asAttributeMapping();
while ( attributeMapping != null && attributeMapping.getDeclaringType() instanceof EmbeddableMappingType ) {
final EmbeddableValuedModelPart declaringModelPart = ( (EmbeddableMappingType) attributeMapping.getDeclaringType() ).getEmbeddedValueMapping();
if ( declaringModelPart == keyPart ) {
return true;
}
attributeMapping = declaringModelPart.asAttributeMapping();
}
}
else if ( keyPart.isVirtual() && keyPart.getNumberOfFetchables() == 1 ) {
return keyPart.getFetchable( 0 ) == modelPart;
}
return false;
}

Expand Down

0 comments on commit d25fb20

Please sign in to comment.