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());
}
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;
}
}
}
Aggregations