Search in sources :

Example 1 with EntityRowIdMapping

use of org.hibernate.metamodel.mapping.EntityRowIdMapping in project hibernate-orm by hibernate.

the class AbstractEntityResultGraphNode method afterInitialize.

@Override
public void afterInitialize(FetchParent fetchParent, DomainResultCreationState creationState) {
    final EntityMappingType entityDescriptor = referencedModelPart.getEntityMappingType();
    final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
    final NavigablePath navigablePath = getNavigablePath();
    final TableGroup entityTableGroup = creationState.getSqlAstCreationState().getFromClauseAccess().getTableGroup(navigablePath);
    final EntityIdentifierNavigablePath identifierNavigablePath = new EntityIdentifierNavigablePath(navigablePath, attributeName(identifierMapping));
    if (navigablePath.getParent() == null && !creationState.forceIdentifierSelection()) {
        identifierFetch = null;
        visitIdentifierMapping(identifierNavigablePath, creationState, identifierMapping, entityTableGroup);
    } else {
        identifierFetch = ((Fetchable) identifierMapping).generateFetch(fetchParent, identifierNavigablePath, FetchTiming.IMMEDIATE, true, null, creationState);
    }
    final EntityDiscriminatorMapping discriminatorMapping = entityDescriptor.getDiscriminatorMapping();
    // No need to fetch the discriminator if this type does not have subclasses
    if (discriminatorMapping != null && entityDescriptor.hasSubclasses()) {
        discriminatorFetch = discriminatorMapping.generateFetch(fetchParent, navigablePath.append(EntityDiscriminatorMapping.ROLE_NAME), FetchTiming.IMMEDIATE, true, null, creationState);
    } else {
        discriminatorFetch = null;
    }
    final EntityRowIdMapping rowIdMapping = entityDescriptor.getRowIdMapping();
    if (rowIdMapping == null) {
        rowIdResult = null;
    } else {
        rowIdResult = rowIdMapping.createDomainResult(navigablePath.append(rowIdMapping.getRowIdName()), entityTableGroup, AbstractEntityPersister.ROWID_ALIAS, creationState);
    }
    super.afterInitialize(fetchParent, creationState);
}
Also used : NavigablePath(org.hibernate.query.spi.NavigablePath) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) EntityRowIdMapping(org.hibernate.metamodel.mapping.EntityRowIdMapping) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) EntityDiscriminatorMapping(org.hibernate.metamodel.mapping.EntityDiscriminatorMapping)

Aggregations

EntityDiscriminatorMapping (org.hibernate.metamodel.mapping.EntityDiscriminatorMapping)1 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)1 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)1 EntityRowIdMapping (org.hibernate.metamodel.mapping.EntityRowIdMapping)1 NavigablePath (org.hibernate.query.spi.NavigablePath)1 EntityIdentifierNavigablePath (org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath)1 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)1