Search in sources :

Example 1 with FetchParentAccess

use of org.hibernate.sql.results.graph.FetchParentAccess 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 2 with FetchParentAccess

use of org.hibernate.sql.results.graph.FetchParentAccess in project hibernate-orm by hibernate.

the class AbstractEmbeddableInitializer method initializeInstance.

@Override
public void initializeInstance(RowProcessingState processingState) {
    EmbeddableLoadingLogger.INSTANCE.debugf("Initializing composite instance [%s]", navigablePath);
    if (compositeInstance == NULL_MARKER) {
        // we already know it is null
        return;
    }
    if (!usesStandardInstatiation) {
        // we have a custom instantiator
        if (compositeInstance != null) {
            return;
        }
    }
    stateInjected = false;
    extractRowState(processingState);
    prepareCompositeInstance(processingState);
    handleParentInjection(processingState);
    if (compositeInstance != NULL_MARKER) {
        notifyResolutionListeners(compositeInstance);
        if (compositeInstance instanceof HibernateProxy) {
            final Initializer parentInitializer = processingState.resolveInitializer(navigablePath.getParent());
            if (parentInitializer != this) {
                ((FetchParentAccess) parentInitializer).registerResolutionListener((entity) -> {
                    representationEmbeddable.setValues(entity, rowState);
                    stateInjected = true;
                });
            } else {
                // At this point, createEmptyCompositesEnabled is always true, so we generate
                // the composite instance.
                // 
                // NOTE: `valuesAccess` is set to null to indicate that all values are null,
                // as opposed to returning the all-null value array.  the instantiator
                // interprets that as the values are not known or were all null.
                final Object target = representationStrategy.getInstantiator().instantiate(this, sessionFactory);
                stateInjected = true;
                ((HibernateProxy) compositeInstance).getHibernateLazyInitializer().setImplementation(target);
            }
        } else if (stateAllNull == FALSE && stateInjected != TRUE) {
            representationEmbeddable.setValues(compositeInstance, rowState);
            stateInjected = true;
        }
    }
}
Also used : AbstractFetchParentAccess(org.hibernate.sql.results.graph.AbstractFetchParentAccess) FetchParentAccess(org.hibernate.sql.results.graph.FetchParentAccess) EntityInitializer(org.hibernate.sql.results.graph.entity.EntityInitializer) CollectionInitializer(org.hibernate.sql.results.graph.collection.CollectionInitializer) Initializer(org.hibernate.sql.results.graph.Initializer) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Aggregations

AbstractFetchParentAccess (org.hibernate.sql.results.graph.AbstractFetchParentAccess)2 FetchParentAccess (org.hibernate.sql.results.graph.FetchParentAccess)2 Initializer (org.hibernate.sql.results.graph.Initializer)2 CollectionInitializer (org.hibernate.sql.results.graph.collection.CollectionInitializer)2 EntityInitializer (org.hibernate.sql.results.graph.entity.EntityInitializer)2 NotYetImplementedFor6Exception (org.hibernate.NotYetImplementedFor6Exception)1 HibernateProxy (org.hibernate.proxy.HibernateProxy)1 NavigablePath (org.hibernate.query.spi.NavigablePath)1