HHH-17832 Register projection usage for circular bidirectional fetch

This commit is contained in:
Marco Belladelli 2024-03-11 11:41:31 +01:00
parent 747a1024da
commit bcbae00552
2 changed files with 13 additions and 1 deletions

View File

@ -60,6 +60,7 @@ import org.hibernate.metamodel.mapping.VirtualModelPart;
import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.persister.collection.AbstractCollectionPersister; import org.hibernate.persister.collection.AbstractCollectionPersister;
import org.hibernate.persister.entity.AbstractEntityPersister; import org.hibernate.persister.entity.AbstractEntityPersister;
import org.hibernate.persister.entity.EntityNameUse;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.JoinedSubclassEntityPersister; import org.hibernate.persister.entity.JoinedSubclassEntityPersister;
import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.property.access.spi.PropertyAccess;
@ -1300,6 +1301,12 @@ public class ToOneAttributeMapping
final FromClauseAccess fromClauseAccess = creationState.getSqlAstCreationState().getFromClauseAccess(); final FromClauseAccess fromClauseAccess = creationState.getSqlAstCreationState().getFromClauseAccess();
final TableGroup tableGroup = fromClauseAccess.getTableGroup( referencedNavigablePath ); final TableGroup tableGroup = fromClauseAccess.getTableGroup( referencedNavigablePath );
fromClauseAccess.registerTableGroup( fetchablePath, tableGroup ); fromClauseAccess.registerTableGroup( fetchablePath, tableGroup );
// Register a PROJECTION usage as we're effectively selecting the bidirectional association
creationState.getSqlAstCreationState().registerEntityNameUsage(
tableGroup,
EntityNameUse.PROJECTION,
entityMappingType.getEntityName()
);
return buildEntityFetchJoined( return buildEntityFetchJoined(
fetchParent, fetchParent,
this, this,

View File

@ -3047,7 +3047,12 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
TableGroup tableGroup, TableGroup tableGroup,
EntityNameUse entityNameUse, EntityNameUse entityNameUse,
String hibernateEntityName) { String hibernateEntityName) {
registerEntityNameUsage( tableGroup, entityNameUse, hibernateEntityName, false ); registerEntityNameUsage(
tableGroup,
entityNameUse,
hibernateEntityName,
entityNameUse.getKind() == EntityNameUse.UseKind.PROJECTION
);
} }
private void registerEntityNameUsage( private void registerEntityNameUsage(