Search in sources :

Example 1 with EntityDelayedResultImpl

use of org.hibernate.sql.results.graph.entity.internal.EntityDelayedResultImpl in project hibernate-orm by hibernate.

the class ToOneAttributeMapping method createDelayedDomainResult.

@Override
public <T> DomainResult<T> createDelayedDomainResult(NavigablePath navigablePath, TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) {
    // and if the FK refers to a non-PK, in which case we must load the whole entity
    if (sideNature == ForeignKeyDescriptor.Nature.TARGET || referencedPropertyName != null) {
        creationState.getSqlAstCreationState().getFromClauseAccess().resolveTableGroup(navigablePath, np -> {
            final TableGroupJoin tableGroupJoin = createTableGroupJoin(navigablePath, tableGroup, null, getDefaultSqlAstJoinType(tableGroup), true, false, creationState.getSqlAstCreationState());
            tableGroup.addTableGroupJoin(tableGroupJoin);
            return tableGroupJoin.getJoinedGroup();
        });
    }
    if (referencedPropertyName == null) {
        return new EntityDelayedResultImpl(navigablePath.append(EntityIdentifierMapping.ROLE_LOCAL_NAME), this, tableGroup, creationState);
    } else {
        // We don't support proxies based on a non-PK yet, so we must fetch the whole entity
        final EntityResultImpl entityResult = new EntityResultImpl(navigablePath, this, tableGroup, null, creationState);
        entityResult.afterInitialize(entityResult, creationState);
        // noinspection unchecked
        return entityResult;
    }
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) EntityResultImpl(org.hibernate.sql.results.graph.entity.internal.EntityResultImpl) EntityDelayedResultImpl(org.hibernate.sql.results.graph.entity.internal.EntityDelayedResultImpl)

Aggregations

TableGroupJoin (org.hibernate.sql.ast.tree.from.TableGroupJoin)1 EntityDelayedResultImpl (org.hibernate.sql.results.graph.entity.internal.EntityDelayedResultImpl)1 EntityResultImpl (org.hibernate.sql.results.graph.entity.internal.EntityResultImpl)1