Search in sources :

Example 1 with CollectionInitializer

use of org.hibernate.sql.results.graph.collection.CollectionInitializer 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)

Aggregations

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