HHH-16191 Fix issues uncovered by recent not-found fetchin changes

This commit is contained in:
Christian Beikov 2023-03-02 23:03:48 +01:00
parent 6f5102ffd2
commit c67dbc0013
6 changed files with 24 additions and 4 deletions

View File

@ -670,7 +670,7 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr
)
);
}
fetchable = (Fetchable) ( (FetchableContainer) fetchable ).findSubPart( propertyPathParts[i], null );
fetchable = (Fetchable) ( (FetchableContainer) fetchable.getPartMappingType() ).findSubPart( propertyPathParts[i], null );
navigablePath = navigablePath.append( fetchable.getFetchableName() );
}

View File

@ -1829,7 +1829,7 @@ public abstract class AbstractEntityPersister
return fetches.build();
}
protected boolean isSelectable(FetchParent fetchParent, Fetchable fetchable) {
public boolean isSelectable(FetchParent fetchParent, Fetchable fetchable) {
if ( fetchParent instanceof EmbeddableResultGraphNode ) {
return true;
}
@ -4159,6 +4159,11 @@ public abstract class AbstractEntityPersister
return entityMetamodel.getCascadeStyles();
}
@Override
public boolean isPropertySelectable(int propertyNumber) {
return propertySelectable[propertyNumber];
}
@Override
public final Class<?> getMappedClass() {
return this.getMappedJavaType().getJavaTypeClass();

View File

@ -674,6 +674,10 @@ public interface EntityPersister extends EntityMappingType, RootTableGroupProduc
*/
CascadeStyle[] getPropertyCascadeStyles();
default boolean isPropertySelectable(int propertyNumber) {
return true;
}
/**
* Get the identifier type
*/

View File

@ -29,6 +29,7 @@ import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping;
import org.hibernate.metamodel.mapping.internal.BasicValuedCollectionPart;
import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping;
import org.hibernate.persister.entity.AbstractEntityPersister;
import org.hibernate.spi.EntityIdentifierNavigablePath;
import org.hibernate.spi.NavigablePath;
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
@ -428,6 +429,11 @@ public class DomainResultCreationStateImpl
private Consumer<Fetchable> createFetchableConsumer(FetchParent fetchParent, ImmutableFetchList.Builder fetches) {
return fetchable -> {
final FetchableContainer parentMappingType = fetchParent.getReferencedMappingContainer();
if ( parentMappingType instanceof AbstractEntityPersister
&& !( ( (AbstractEntityPersister) parentMappingType ).isSelectable( fetchParent, fetchable ) ) ) {
return;
}
final String fetchableName = fetchable.getFetchableName();
Map.Entry<String, NavigablePath> currentEntry;
if ( relativePathStack.isEmpty() ) {

View File

@ -187,7 +187,7 @@ public class DynamicResultBuilderEntityStandard
final NavigablePath elementNavigablePath;
if ( fetchable instanceof PluralAttributeMapping ) {
collectionTableGroup = fromClauseAccess.getTableGroup( navigablePath );
elementNavigablePath = navigablePath.append( fetchable.getPartName() );
elementNavigablePath = navigablePath.append( CollectionPart.Nature.ELEMENT.getName() );
}
else {
collectionTableGroup = null;

View File

@ -323,7 +323,12 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
resultBuilderEntity.addProperty( loadable.getIdentifierPropertyName(), identifierAliases );
}
for ( String propertyName : loadable.getPropertyNames() ) {
final String[] propertyNames = loadable.getPropertyNames();
for ( int i = 0; i < propertyNames.length; i++ ) {
if ( !loadable.isPropertySelectable( i ) ) {
continue;
}
final String propertyName = propertyNames[i];
final String[] columnAliases = loadable.getSubclassPropertyColumnAliases( propertyName, suffix );
final Type propertyType = loadable.getPropertyType( propertyName );
addFetchBuilder(