Search in sources :

Example 6 with NotYetImplementedFor6Exception

use of org.hibernate.NotYetImplementedFor6Exception in project hibernate-orm by hibernate.

the class Builders method attributeResult.

public static ResultBuilder attributeResult(String columnAlias, String entityName, String attributePath, SessionFactoryImplementor sessionFactory) {
    if (attributePath.contains(".")) {
        throw new NotYetImplementedFor6Exception("Support for defining a NativeQuery attribute result based on a composite path is not yet implemented");
    }
    final RuntimeMetamodels runtimeMetamodels = sessionFactory.getRuntimeMetamodels();
    final String fullEntityName = runtimeMetamodels.getMappingMetamodel().getImportedName(entityName);
    final EntityPersister entityMapping = runtimeMetamodels.getMappingMetamodel().findEntityDescriptor(fullEntityName);
    if (entityMapping == null) {
        throw new IllegalArgumentException("Could not locate entity mapping : " + fullEntityName);
    }
    final AttributeMapping attributeMapping = entityMapping.findAttributeMapping(attributePath);
    if (attributeMapping == null) {
        throw new IllegalArgumentException("Could not locate attribute mapping : " + fullEntityName + "." + attributePath);
    }
    if (attributeMapping instanceof SingularAttributeMapping) {
        final SingularAttributeMapping singularAttributeMapping = (SingularAttributeMapping) attributeMapping;
        return new DynamicResultBuilderAttribute(singularAttributeMapping, columnAlias, fullEntityName, attributePath);
    }
    throw new IllegalArgumentException(String.format(Locale.ROOT, "Specified attribute mapping [%s.%s] not a basic attribute: %s", fullEntityName, attributePath, attributeMapping));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) DynamicResultBuilderAttribute(org.hibernate.query.results.dynamic.DynamicResultBuilderAttribute) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) RuntimeMetamodels(org.hibernate.metamodel.RuntimeMetamodels) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping)

Example 7 with NotYetImplementedFor6Exception

use of org.hibernate.NotYetImplementedFor6Exception in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method determineValueMapping.

protected MappingModelExpressible<?> determineValueMapping(SqmParameter<?> sqmParameter) {
    log.debugf("Determining mapping-model type for SqmParameter : %s", sqmParameter);
    final QueryParameterImplementor<?> queryParameter = domainParameterXref.getQueryParameter(sqmParameter);
    final QueryParameterBinding<?> binding = domainParameterBindings.getBinding(queryParameter);
    BindableType<?> paramType = binding.getBindType();
    if (paramType == null) {
        paramType = queryParameter.getHibernateType();
        if (paramType == null) {
            paramType = sqmParameter.getAnticipatedType();
        }
    }
    if (paramType == null) {
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        if (inferredValueMapping != null) {
            return inferredValueMapping;
        }
        // Default to the Object type
        return basicType(Object.class);
    } else if (paramType instanceof MappingModelExpressible<?>) {
        final MappingModelExpressible<?> paramModelType = (MappingModelExpressible<?>) paramType;
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        // Prefer the model part type instead of the bind type if possible as the model part type contains size information
        if (inferredValueMapping instanceof ModelPart) {
            final JdbcMapping paramJdbcMapping = paramModelType.getJdbcMappings().get(0);
            final JdbcMapping inferredJdbcMapping = inferredValueMapping.getJdbcMappings().get(0);
            // If the bind type has a different JDBC type, we prefer that
            if (paramJdbcMapping.getJdbcType() == inferredJdbcMapping.getJdbcType()) {
                return inferredValueMapping;
            }
        }
        return paramModelType;
    } else if (sqmParameter.getAnticipatedType() == null) {
        // this should indicate the condition that the user query did not define an
        // explicit type in regard to this parameter.  Here we should prefer the
        // inferrable type and fallback to resolving the binding type
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        if (inferredValueMapping != null) {
            return inferredValueMapping;
        }
    } else if (paramType instanceof EntityDomainType) {
        // In JPA Criteria, it is possible to define a parameter of an entity type,
        // but that should infer the mapping type from context,
        // otherwise this would default to binding the PK which might be wrong
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        if (inferredValueMapping != null) {
            return inferredValueMapping;
        }
    }
    final SqmExpressible<?> paramSqmType = paramType.resolveExpressible(creationContext.getSessionFactory());
    if (paramSqmType instanceof SqmPath) {
        final SqmPath<?> sqmPath = (SqmPath<?>) paramSqmType;
        final NavigablePath navigablePath = sqmPath.getNavigablePath();
        if (navigablePath.getParent() != null) {
            final TableGroup tableGroup = getFromClauseAccess().getTableGroup(navigablePath.getParent());
            return tableGroup.getModelPart().findSubPart(navigablePath.getLocalName(), null);
        }
        return getFromClauseAccess().getTableGroup(navigablePath).getModelPart();
    }
    if (paramSqmType instanceof BasicValuedMapping) {
        return (BasicValuedMapping) paramSqmType;
    }
    if (paramSqmType instanceof CompositeSqmPathSource) {
        // Try to infer the value mapping since the other side apparently is a path source
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        if (inferredValueMapping != null) {
            return inferredValueMapping;
        }
        throw new NotYetImplementedFor6Exception("Support for embedded-valued parameters not yet implemented");
    }
    if (paramSqmType instanceof SqmPathSource<?> || paramSqmType instanceof BasicDomainType<?>) {
        // Try to infer the value mapping since the other side apparently is a path source
        final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
        if (inferredValueMapping != null) {
            return inferredValueMapping;
        }
        return getTypeConfiguration().getBasicTypeForJavaType(paramSqmType.getExpressibleJavaType().getJavaTypeClass());
    }
    throw new ConversionException("Could not determine ValueMapping for SqmParameter: " + sqmParameter);
}
Also used : NavigablePath(org.hibernate.query.spi.NavigablePath) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart) ModelPart(org.hibernate.metamodel.mapping.ModelPart) EntityValuedModelPart(org.hibernate.metamodel.mapping.EntityValuedModelPart) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) SelfInterpretingSqmPath(org.hibernate.query.sqm.sql.internal.SelfInterpretingSqmPath) SqmPath(org.hibernate.query.sqm.tree.domain.SqmPath) DiscriminatorSqmPath(org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath) CompositeSqmPathSource(org.hibernate.metamodel.model.domain.internal.CompositeSqmPathSource) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType)

Example 8 with NotYetImplementedFor6Exception

use of org.hibernate.NotYetImplementedFor6Exception in project hibernate-orm by hibernate.

the class SqmUtil method createValueBindings.

private static void createValueBindings(JdbcParameterBindings jdbcParameterBindings, QueryParameterImplementor<?> domainParam, QueryParameterBinding<?> domainParamBinding, Bindable parameterType, List<JdbcParameter> jdbcParams, Object bindValue, Function<NavigablePath, TableGroup> tableGroupLocator, SharedSessionContractImplementor session) {
    if (parameterType == null) {
        throw new SqlTreeCreationException("Unable to interpret mapping-model type for Query parameter : " + domainParam);
    }
    if (parameterType instanceof EntityIdentifierMapping) {
        final EntityIdentifierMapping identifierMapping = (EntityIdentifierMapping) parameterType;
        final EntityMappingType entityMapping = identifierMapping.findContainingEntityMapping();
        if (entityMapping.getRepresentationStrategy().getInstantiator().isInstance(bindValue, session.getFactory())) {
            bindValue = identifierMapping.getIdentifier(bindValue);
        }
    } else if (parameterType instanceof EntityMappingType) {
        final EntityIdentifierMapping identifierMapping = ((EntityMappingType) parameterType).getIdentifierMapping();
        final EntityMappingType entityMapping = identifierMapping.findContainingEntityMapping();
        parameterType = identifierMapping;
        if (entityMapping.getRepresentationStrategy().getInstantiator().isInstance(bindValue, session.getFactory())) {
            bindValue = identifierMapping.getIdentifier(bindValue);
        }
    } else if (parameterType instanceof EntityAssociationMapping) {
        EntityAssociationMapping association = (EntityAssociationMapping) parameterType;
        bindValue = association.getForeignKeyDescriptor().getAssociationKeyFromSide(bindValue, association.getSideNature().inverse(), session);
        parameterType = association.getForeignKeyDescriptor();
    } else if (parameterType instanceof PluralAttributeMapping) {
        // for now, let's blow up and see where this happens and fix the specifics...
        throw new NotYetImplementedFor6Exception("Binding parameters whose inferred type comes from plural attribute not yet implemented");
    }
    int offset = jdbcParameterBindings.registerParametersForEachJdbcValue(bindValue, Clause.IRRELEVANT, parameterType, jdbcParams, session);
    assert offset == jdbcParams.size();
}
Also used : EntityAssociationMapping(org.hibernate.metamodel.mapping.EntityAssociationMapping) SqlTreeCreationException(org.hibernate.sql.ast.SqlTreeCreationException) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType)

Example 9 with NotYetImplementedFor6Exception

use of org.hibernate.NotYetImplementedFor6Exception in project hibernate-orm by hibernate.

the class CollectionType method getKeyOfOwner.

/**
 * Get the key value from the owning entity instance, usually the identifier, but might be some
 * other unique key, in the case of property-ref
 *
 * @param owner The collection owner
 * @param session The session from which the request is originating.
 * @return The collection owner's key
 */
public Object getKeyOfOwner(Object owner, SharedSessionContractImplementor session) {
    final PersistenceContext pc = session.getPersistenceContextInternal();
    EntityEntry entityEntry = pc.getEntry(owner);
    if (entityEntry == null) {
        // projection, perhaps get rid of it and throw an exception
        return null;
    }
    if (foreignKeyPropertyName == null) {
        return entityEntry.getId();
    } else {
        // TODO: at the point where we are resolving collection references, we don't
        // know if the uk value has been resolved (depends if it was earlier or
        // later in the mapping document) - now, we could try and use e.getStatus()
        // to decide to semiResolve(), trouble is that initializeEntity() reuses
        // the same array for resolved and hydrated values
        Object id;
        if (entityEntry.getLoadedState() != null) {
            id = entityEntry.getLoadedValue(foreignKeyPropertyName);
        } else {
            id = entityEntry.getPersister().getPropertyValue(owner, foreignKeyPropertyName);
        }
        // NOTE VERY HACKISH WORKAROUND!!
        // TODO: Fix this so it will work for non-POJO entity mode
        Type keyType = getPersister(session).getKeyType();
        Class<?> returnedClass = keyType.getReturnedClass();
        if (!returnedClass.isInstance(id)) {
            // todo (6.0) :
            throw new NotYetImplementedFor6Exception("Re-work support for semi-resolve");
        // id = keyType.semiResolve(
        // entityEntry.getLoadedValue( foreignKeyPropertyName ),
        // session,
        // owner
        // );
        }
        return id;
    }
}
Also used : EntityEntry(org.hibernate.engine.spi.EntityEntry) PersistenceContext(org.hibernate.engine.spi.PersistenceContext) MarkerObject(org.hibernate.internal.util.MarkerObject) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception)

Example 10 with NotYetImplementedFor6Exception

use of org.hibernate.NotYetImplementedFor6Exception in project hibernate-orm by hibernate.

the class MappingModelCreationHelper method buildSingularAssociationAttributeMapping.

public static ToOneAttributeMapping buildSingularAssociationAttributeMapping(String attrName, NavigableRole navigableRole, int stateArrayPosition, Property bootProperty, ManagedMappingType declaringType, EntityPersister declaringEntityPersister, EntityType attrType, PropertyAccess propertyAccess, CascadeStyle cascadeStyle, MappingModelCreationProcess creationProcess) {
    if (bootProperty.getValue() instanceof ToOne) {
        final ToOne value = (ToOne) bootProperty.getValue();
        final EntityPersister entityPersister = creationProcess.getEntityPersister(value.getReferencedEntityName());
        final StateArrayContributorMetadataAccess stateArrayContributorMetadataAccess = getStateArrayContributorMetadataAccess(bootProperty, attrType, propertyAccess, cascadeStyle, creationProcess);
        SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory();
        final AssociationType type = (AssociationType) bootProperty.getType();
        final FetchStyle fetchStyle = FetchOptionsHelper.determineFetchStyleByMetadata(bootProperty.getValue().getFetchMode(), type, sessionFactory);
        final FetchTiming fetchTiming;
        final String role = declaringType.getNavigableRole().toString() + "." + bootProperty.getName();
        final boolean lazy = value.isLazy();
        if (lazy && entityPersister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading()) {
            if (value.isUnwrapProxy()) {
                fetchTiming = FetchOptionsHelper.determineFetchTiming(fetchStyle, type, lazy, role, sessionFactory);
            } else if (value instanceof ManyToOne && value.isNullable() && ((ManyToOne) value).isIgnoreNotFound()) {
                fetchTiming = FetchTiming.IMMEDIATE;
            } else {
                fetchTiming = FetchOptionsHelper.determineFetchTiming(fetchStyle, type, lazy, role, sessionFactory);
            }
        } else if (!lazy || value instanceof OneToOne && value.isNullable() || value instanceof ManyToOne && value.isNullable() && ((ManyToOne) value).isIgnoreNotFound()) {
            fetchTiming = FetchTiming.IMMEDIATE;
        } else {
            fetchTiming = FetchOptionsHelper.determineFetchTiming(fetchStyle, type, lazy, role, sessionFactory);
        }
        final ToOneAttributeMapping attributeMapping = new ToOneAttributeMapping(attrName, navigableRole, stateArrayPosition, (ToOne) bootProperty.getValue(), stateArrayContributorMetadataAccess, fetchTiming, fetchStyle, entityPersister, declaringType, declaringEntityPersister, propertyAccess);
        creationProcess.registerForeignKeyPostInitCallbacks("To-one key - " + navigableRole, () -> {
            final Dialect dialect = creationProcess.getCreationContext().getSessionFactory().getJdbcServices().getDialect();
            return MappingModelCreationHelper.interpretToOneKeyDescriptor(attributeMapping, bootProperty, (ToOne) bootProperty.getValue(), null, dialect, creationProcess);
        });
        return attributeMapping;
    } else {
        throw new NotYetImplementedFor6Exception("AnyType support has not yet been implemented");
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ManyToOne(org.hibernate.mapping.ManyToOne) FetchStyle(org.hibernate.engine.FetchStyle) OneToOne(org.hibernate.mapping.OneToOne) StateArrayContributorMetadataAccess(org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess) AssociationType(org.hibernate.type.AssociationType) FetchTiming(org.hibernate.engine.FetchTiming) ToOne(org.hibernate.mapping.ToOne) OneToOne(org.hibernate.mapping.OneToOne) ManyToOne(org.hibernate.mapping.ManyToOne) Dialect(org.hibernate.dialect.Dialect) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception)

Aggregations

NotYetImplementedFor6Exception (org.hibernate.NotYetImplementedFor6Exception)17 EntityPersister (org.hibernate.persister.entity.EntityPersister)8 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)5 BasicValuedModelPart (org.hibernate.metamodel.mapping.BasicValuedModelPart)5 EmbeddableValuedModelPart (org.hibernate.metamodel.mapping.EmbeddableValuedModelPart)5 ModelPart (org.hibernate.metamodel.mapping.ModelPart)5 SelectableMapping (org.hibernate.metamodel.mapping.SelectableMapping)5 CompositeType (org.hibernate.type.CompositeType)5 EntityType (org.hibernate.type.EntityType)5 BasicValue (org.hibernate.mapping.BasicValue)4 OneToOne (org.hibernate.mapping.OneToOne)4 SimpleValue (org.hibernate.mapping.SimpleValue)4 BasicType (org.hibernate.type.BasicType)4 Dialect (org.hibernate.dialect.Dialect)3 Any (org.hibernate.mapping.Any)3 ManyToOne (org.hibernate.mapping.ManyToOne)3 Selectable (org.hibernate.mapping.Selectable)3 ToOne (org.hibernate.mapping.ToOne)3 AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)3 EmbeddableMappingType (org.hibernate.metamodel.mapping.EmbeddableMappingType)3