Search in sources :

Example 1 with NotYetImplementedFor6Exception

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

the class MappingModelCreationHelper method interpretPluralAttributeMappingKeyDescriptor.

private static void interpretPluralAttributeMappingKeyDescriptor(PluralAttributeMappingImpl attributeMapping, Collection bootValueMapping, CollectionPersister collectionDescriptor, ManagedMappingType declaringType, Dialect dialect, MappingModelCreationProcess creationProcess) {
    ModelPart attributeMappingSubPart = null;
    if (!StringHelper.isEmpty(collectionDescriptor.getMappedByProperty())) {
        attributeMappingSubPart = ((ModelPartContainer) attributeMapping.getElementDescriptor().getPartMappingType()).findSubPart(collectionDescriptor.getMappedByProperty(), null);
    }
    if (attributeMappingSubPart instanceof ToOneAttributeMapping) {
        final ToOneAttributeMapping referencedAttributeMapping = (ToOneAttributeMapping) attributeMappingSubPart;
        setReferencedAttributeForeignKeyDescriptor(attributeMapping, referencedAttributeMapping, referencedAttributeMapping.findContainingEntityMapping().getEntityPersister(), collectionDescriptor.getMappedByProperty(), dialect, creationProcess);
        return;
    }
    final KeyValue bootValueMappingKey = bootValueMapping.getKey();
    final Type keyType = bootValueMappingKey.getType();
    final ModelPart fkTarget;
    final String lhsPropertyName = collectionDescriptor.getCollectionType().getLHSPropertyName();
    final boolean isReferenceToPrimaryKey = lhsPropertyName == null;
    final ManagedMappingType keyDeclaringType;
    if (collectionDescriptor.getElementType().isEntityType()) {
        keyDeclaringType = ((QueryableCollection) collectionDescriptor).getElementPersister();
    } else {
        // This is not "really correct" but it is as good as it gets.
        // The key declaring type serves as declaring type for the inverse model part of a FK.
        // Most of the time, there is a proper managed type, but not for basic collections.
        // Since the declaring type is needed for certain operations, we use the one from the target side of the FK
        keyDeclaringType = declaringType;
    }
    if (isReferenceToPrimaryKey) {
        fkTarget = collectionDescriptor.getOwnerEntityPersister().getIdentifierMapping();
    } else {
        fkTarget = declaringType.findAttributeMapping(lhsPropertyName);
    }
    if (keyType instanceof BasicType) {
        assert bootValueMappingKey.getColumnSpan() == 1;
        assert fkTarget instanceof BasicValuedModelPart;
        final BasicValuedModelPart simpleFkTarget = (BasicValuedModelPart) fkTarget;
        final String tableExpression = getTableIdentifierExpression(bootValueMappingKey.getTable(), creationProcess);
        final SelectableMapping keySelectableMapping = SelectableMappingImpl.from(tableExpression, bootValueMappingKey.getSelectables().get(0), (JdbcMapping) keyType, dialect, creationProcess.getSqmFunctionRegistry());
        attributeMapping.setForeignKeyDescriptor(new SimpleForeignKeyDescriptor(keyDeclaringType, simpleFkTarget, null, keySelectableMapping, simpleFkTarget, isReferenceToPrimaryKey, ((SimpleValue) bootValueMappingKey).isConstrained()));
    } else if (fkTarget instanceof EmbeddableValuedModelPart) {
        final EmbeddedForeignKeyDescriptor embeddedForeignKeyDescriptor = buildEmbeddableForeignKeyDescriptor((EmbeddableValuedModelPart) fkTarget, bootValueMapping, keyDeclaringType, collectionDescriptor.getAttributeMapping(), false, dialect, creationProcess);
        attributeMapping.setForeignKeyDescriptor(embeddedForeignKeyDescriptor);
    } else {
        throw new NotYetImplementedFor6Exception("Support for " + fkTarget.getClass() + " foreign keys not yet implemented: " + bootValueMapping.getRole());
    }
}
Also used : ManagedMappingType(org.hibernate.metamodel.mapping.ManagedMappingType) SelectableMapping(org.hibernate.metamodel.mapping.SelectableMapping) KeyValue(org.hibernate.mapping.KeyValue) BasicType(org.hibernate.type.BasicType) VirtualModelPart(org.hibernate.metamodel.mapping.VirtualModelPart) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) ModelPart(org.hibernate.metamodel.mapping.ModelPart) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) SimpleValue(org.hibernate.mapping.SimpleValue) BasicType(org.hibernate.type.BasicType) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) CollectionMappingType(org.hibernate.metamodel.mapping.CollectionMappingType) JavaType(org.hibernate.type.descriptor.java.JavaType) EntityType(org.hibernate.type.EntityType) ComponentType(org.hibernate.type.ComponentType) CompositeType(org.hibernate.type.CompositeType) ManagedMappingType(org.hibernate.metamodel.mapping.ManagedMappingType) EmbeddableMappingType(org.hibernate.metamodel.mapping.EmbeddableMappingType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception)

Example 2 with NotYetImplementedFor6Exception

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

the class MappingModelCreationHelper method interpretMapKey.

private static CollectionPart interpretMapKey(Collection bootValueMapping, CollectionPersister collectionDescriptor, String tableExpression, String sqlAliasStem, Dialect dialect, MappingModelCreationProcess creationProcess) {
    assert bootValueMapping instanceof IndexedCollection;
    final IndexedCollection indexedCollection = (IndexedCollection) bootValueMapping;
    final Value bootMapKeyDescriptor = indexedCollection.getIndex();
    if (bootMapKeyDescriptor instanceof BasicValue) {
        final BasicValue basicValue = (BasicValue) bootMapKeyDescriptor;
        final SelectableMapping selectableMapping = SelectableMappingImpl.from(tableExpression, basicValue.getSelectables().get(0), basicValue.resolve().getJdbcMapping(), dialect, creationProcess.getSqmFunctionRegistry());
        return new BasicValuedCollectionPart(collectionDescriptor, CollectionPart.Nature.INDEX, basicValue.resolve().getValueConverter(), selectableMapping);
    }
    if (bootMapKeyDescriptor instanceof Component) {
        final Component component = (Component) bootMapKeyDescriptor;
        final CompositeType compositeType = (CompositeType) component.getType();
        final EmbeddableMappingTypeImpl mappingType = EmbeddableMappingTypeImpl.from(component, compositeType, inflightDescriptor -> new EmbeddedCollectionPart(collectionDescriptor, CollectionPart.Nature.INDEX, inflightDescriptor, // parent-injection
        component.getParentProperty(), tableExpression, sqlAliasStem), creationProcess);
        return (CollectionPart) mappingType.getEmbeddedValueMapping();
    }
    if (bootMapKeyDescriptor instanceof OneToMany || bootMapKeyDescriptor instanceof ToOne) {
        final EntityType indexEntityType = (EntityType) collectionDescriptor.getIndexType();
        final EntityPersister associatedEntity = creationProcess.getEntityPersister(indexEntityType.getAssociatedEntityName());
        final EntityCollectionPart indexDescriptor = new EntityCollectionPart(collectionDescriptor, CollectionPart.Nature.INDEX, bootMapKeyDescriptor, associatedEntity, creationProcess);
        creationProcess.registerInitializationCallback("PluralAttributeMapping( " + bootValueMapping.getRole() + ") - index descriptor", () -> {
            indexDescriptor.finishInitialization(collectionDescriptor, bootValueMapping, indexEntityType.getRHSUniqueKeyPropertyName(), creationProcess);
            return true;
        });
        return indexDescriptor;
    }
    throw new NotYetImplementedFor6Exception("Support for plural attributes with index type [" + bootMapKeyDescriptor + "] not yet implemented");
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SelectableMapping(org.hibernate.metamodel.mapping.SelectableMapping) OneToMany(org.hibernate.mapping.OneToMany) BasicValue(org.hibernate.mapping.BasicValue) EntityType(org.hibernate.type.EntityType) SimpleValue(org.hibernate.mapping.SimpleValue) Value(org.hibernate.mapping.Value) BasicValue(org.hibernate.mapping.BasicValue) SortableValue(org.hibernate.mapping.SortableValue) KeyValue(org.hibernate.mapping.KeyValue) ToOne(org.hibernate.mapping.ToOne) OneToOne(org.hibernate.mapping.OneToOne) ManyToOne(org.hibernate.mapping.ManyToOne) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) Component(org.hibernate.mapping.Component) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) IndexedCollection(org.hibernate.mapping.IndexedCollection) CompositeType(org.hibernate.type.CompositeType)

Example 3 with NotYetImplementedFor6Exception

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

the class MappingMetamodelImpl method resolveMappingExpressible.

@Override
public MappingModelExpressible<?> resolveMappingExpressible(SqmExpressible<?> sqmExpressible, Function<NavigablePath, TableGroup> tableGroupLocator) {
    if (sqmExpressible instanceof SqmPath) {
        final SqmPath<?> sqmPath = (SqmPath<?>) sqmExpressible;
        final NavigablePath navigablePath = sqmPath.getNavigablePath();
        if (navigablePath.getParent() != null) {
            final TableGroup parentTableGroup = tableGroupLocator.apply(navigablePath.getParent());
            return parentTableGroup.getModelPart().findSubPart(navigablePath.getLocalName(), null);
        }
        return tableGroupLocator.apply(navigablePath.getParent()).getModelPart();
    }
    if (sqmExpressible instanceof BasicType<?>) {
        return (BasicType<?>) sqmExpressible;
    }
    if (sqmExpressible instanceof BasicSqmPathSource<?>) {
        return getTypeConfiguration().getBasicTypeForJavaType(((BasicSqmPathSource<?>) sqmExpressible).getJavaType());
    }
    if (sqmExpressible instanceof SqmFieldLiteral) {
        return getTypeConfiguration().getBasicTypeForJavaType(((SqmFieldLiteral<?>) sqmExpressible).getJavaType());
    }
    if (sqmExpressible instanceof CompositeSqmPathSource) {
        throw new NotYetImplementedFor6Exception("Resolution of embedded-valued SqmExpressible nodes not yet implemented");
    }
    if (sqmExpressible instanceof EmbeddableTypeImpl) {
        return (MappingModelExpressible<?>) sqmExpressible;
    }
    if (sqmExpressible instanceof EntityDomainType<?>) {
        return getEntityDescriptor(((EntityDomainType<?>) sqmExpressible).getHibernateEntityName());
    }
    if (sqmExpressible instanceof TupleType<?>) {
        final MappingModelExpressible<?> mappingModelExpressible = tupleTypeCache.get(sqmExpressible);
        if (mappingModelExpressible != null) {
            return mappingModelExpressible;
        }
        final TupleType<?> tupleType = (TupleType<?>) sqmExpressible;
        final MappingModelExpressible<?>[] components = new MappingModelExpressible<?>[tupleType.componentCount()];
        for (int i = 0; i < components.length; i++) {
            components[i] = resolveMappingExpressible(tupleType.get(i), tableGroupLocator);
        }
        final MappingModelExpressible<?> createdMappingModelExpressible = new TupleMappingModelExpressible(components);
        final MappingModelExpressible<?> existingMappingModelExpressible = tupleTypeCache.putIfAbsent(tupleType, createdMappingModelExpressible);
        return existingMappingModelExpressible == null ? createdMappingModelExpressible : existingMappingModelExpressible;
    }
    return null;
}
Also used : NavigablePath(org.hibernate.query.spi.NavigablePath) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) BasicType(org.hibernate.type.BasicType) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) SqmPath(org.hibernate.query.sqm.tree.domain.SqmPath) TupleType(org.hibernate.metamodel.model.domain.TupleType) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType) SqmFieldLiteral(org.hibernate.query.sqm.tree.expression.SqmFieldLiteral)

Example 4 with NotYetImplementedFor6Exception

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

the class AbstractEmbeddableInitializer method determineParentInstance.

private Object determineParentInstance(RowProcessingState processingState) {
    // or at least the fetch-parent of the collection could get passed.
    if (fetchParentAccess != null) {
        // the embeddable being initialized is a fetch, so use the fetchParentAccess
        // to get the parent reference
        // 
        // at the moment, this uses the legacy behavior of injecting the "first
        // containing entity" as the parent.  however,
        // todo (6.x) - allow injection of containing composite as parent if
        // it is the direct parent
        final FetchParentAccess firstEntityDescriptorAccess = fetchParentAccess.findFirstEntityDescriptorAccess();
        return firstEntityDescriptorAccess.getInitializedInstance();
    }
    // Otherwise, fallback to determining the parent-initializer by path
    // todo (6.0) - this is the part that should be "subsumed" based on the
    // comment above
    final NavigablePath parentPath = navigablePath.getParent();
    if (parentPath == null) {
        return null;
    }
    final Initializer parentInitializer = processingState.resolveInitializer(parentPath);
    if (parentInitializer instanceof CollectionInitializer) {
        return ((CollectionInitializer) parentInitializer).getCollectionInstance().getOwner();
    }
    if (parentInitializer instanceof EntityInitializer) {
        return ((EntityInitializer) parentInitializer).getEntityInstance();
    }
    throw new NotYetImplementedFor6Exception(getClass());
}
Also used : AbstractFetchParentAccess(org.hibernate.sql.results.graph.AbstractFetchParentAccess) FetchParentAccess(org.hibernate.sql.results.graph.FetchParentAccess) NavigablePath(org.hibernate.query.spi.NavigablePath) EntityInitializer(org.hibernate.sql.results.graph.entity.EntityInitializer) CollectionInitializer(org.hibernate.sql.results.graph.collection.CollectionInitializer) Initializer(org.hibernate.sql.results.graph.Initializer) EntityInitializer(org.hibernate.sql.results.graph.entity.EntityInitializer) CollectionInitializer(org.hibernate.sql.results.graph.collection.CollectionInitializer) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception)

Example 5 with NotYetImplementedFor6Exception

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

the class MultiNaturalIdLoaderStandard method multiLoad.

@Override
public <K> List<E> multiLoad(K[] naturalIds, MultiNaturalIdLoadOptions options, SharedSessionContractImplementor session) {
    if (naturalIds == null) {
        throw new IllegalArgumentException("`naturalIds` is null");
    }
    if (naturalIds.length == 0) {
        return Collections.emptyList();
    }
    if (LoadingLogger.LOGGER.isTraceEnabled()) {
        LoadingLogger.LOGGER.tracef("Starting multi natural-id loading for `%s`", entityDescriptor.getEntityName());
    }
    final SessionFactoryImplementor sessionFactory = session.getFactory();
    final int maxBatchSize;
    if (options.getBatchSize() != null && options.getBatchSize() > 0) {
        maxBatchSize = options.getBatchSize();
    } else {
        maxBatchSize = session.getJdbcServices().getJdbcEnvironment().getDialect().getDefaultBatchLoadSizingStrategy().determineOptimalBatchLoadSize(entityDescriptor.getNaturalIdMapping().getJdbcTypeCount(), naturalIds.length, sessionFactory.getSessionFactoryOptions().inClauseParameterPaddingEnabled());
    }
    final int batchSize = Math.min(maxBatchSize, naturalIds.length);
    final LockOptions lockOptions = (options.getLockOptions() == null) ? new LockOptions(LockMode.NONE) : options.getLockOptions();
    final MultiNaturalIdLoadingBatcher batcher = new MultiNaturalIdLoadingBatcher(entityDescriptor, entityDescriptor.getNaturalIdMapping(), batchSize, (naturalId, session1) -> {
        // todo (6.0) : use this to help create the ordered results
        return entityDescriptor.getNaturalIdMapping().normalizeInput(naturalId, session);
    }, session.getLoadQueryInfluencers(), lockOptions, sessionFactory);
    final List<E> results = batcher.multiLoad(naturalIds, options, session);
    if (results.size() == 1) {
        return results;
    }
    if (options.isOrderReturnEnabled()) {
        throw new NotYetImplementedFor6Exception(getClass());
    }
    return results;
}
Also used : LockOptions(org.hibernate.LockOptions) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) 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