Search in sources :

Example 1 with WalkingException

use of org.hibernate.persister.walking.spi.WalkingException in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method finishingEntityIdentifier.

@Override
public void finishingEntityIdentifier(EntityIdentifierDefinition entityIdentifierDefinition) {
    // only pop from stack if the current source is ExpandingEntityIdentifierDescription..
    final ExpandingFetchSource currentSource = currentSource();
    if (!ExpandingEntityIdentifierDescription.class.isInstance(currentSource)) {
        // in this case, the current source should be the entity that owns entityIdentifierDefinition
        if (!EntityReference.class.isInstance(currentSource)) {
            throw new WalkingException("Unexpected state in FetchSource stack");
        }
        final EntityReference entityReference = (EntityReference) currentSource;
        if (entityReference.getEntityPersister().getEntityKeyDefinition() != entityIdentifierDefinition) {
            throw new WalkingException(String.format("Encountered unexpected fetch owner [%s] in stack while processing entity identifier for [%s]", entityReference.getEntityPersister().getEntityName(), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName()));
        }
        return;
    }
    // the current source is ExpandingEntityIdentifierDescription...
    final ExpandingEntityIdentifierDescription identifierDescription = (ExpandingEntityIdentifierDescription) popFromStack();
    // and then on the node beforeQuery it (which should be the entity that owns the identifier being described)
    final ExpandingFetchSource entitySource = currentSource();
    if (!EntityReference.class.isInstance(entitySource)) {
        throw new WalkingException("Unexpected state in FetchSource stack");
    }
    final EntityReference entityReference = (EntityReference) entitySource;
    if (entityReference.getIdentifierDescription() != identifierDescription) {
        throw new WalkingException(String.format("Encountered unexpected fetch owner [%s] in stack while processing entity identifier for [%s]", entityReference.getEntityPersister().getEntityName(), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName()));
    }
    log.tracef("%s Finished entity identifier : %s", StringHelper.repeat("<<", fetchSourceStack.size()), entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName());
}
Also used : ExpandingEntityIdentifierDescription(org.hibernate.loader.plan.build.spi.ExpandingEntityIdentifierDescription) EntityReference(org.hibernate.loader.plan.spi.EntityReference) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) WalkingException(org.hibernate.persister.walking.spi.WalkingException)

Example 2 with WalkingException

use of org.hibernate.persister.walking.spi.WalkingException in project hibernate-orm by hibernate.

the class AbstractExpandingFetchSource method buildBidirectionalEntityReference.

@Override
public BidirectionalEntityReference buildBidirectionalEntityReference(AssociationAttributeDefinition attributeDefinition, FetchStrategy fetchStrategy, EntityReference targetEntityReference) {
    final EntityType fetchedType = (EntityType) attributeDefinition.getType();
    final EntityPersister fetchedPersister = attributeDefinition.toEntityDefinition().getEntityPersister();
    if (fetchedPersister == null) {
        throw new WalkingException(String.format("Unable to locate EntityPersister [%s] for bidirectional entity reference [%s]", fetchedType.getAssociatedEntityName(), attributeDefinition.getName()));
    }
    final BidirectionalEntityReference bidirectionalEntityReference = new BidirectionalEntityReferenceImpl(this, attributeDefinition, targetEntityReference);
    addBidirectionalEntityReference(bidirectionalEntityReference);
    return bidirectionalEntityReference;
}
Also used : EntityType(org.hibernate.type.EntityType) EntityPersister(org.hibernate.persister.entity.EntityPersister) WalkingException(org.hibernate.persister.walking.spi.WalkingException) BidirectionalEntityReference(org.hibernate.loader.plan.spi.BidirectionalEntityReference)

Example 3 with WalkingException

use of org.hibernate.persister.walking.spi.WalkingException in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method startingCollectionIndex.

@Override
public void startingCollectionIndex(CollectionIndexDefinition indexDefinition) {
    final Type indexType = indexDefinition.getType();
    log.tracef("%s Starting collection index graph : %s", StringHelper.repeat(">>", fetchSourceStack.size()), indexDefinition.getCollectionDefinition().getCollectionPersister().getRole());
    final CollectionReference collectionReference = currentCollection();
    final CollectionFetchableIndex indexGraph = collectionReference.getIndexGraph();
    if (indexType.isEntityType() || indexType.isComponentType()) {
        if (indexGraph == null) {
            throw new WalkingException("CollectionReference did not return an expected index graph : " + indexDefinition.getCollectionDefinition().getCollectionPersister().getRole());
        }
        if (!indexType.isAnyType()) {
            pushToStack((ExpandingFetchSource) indexGraph);
        }
    } else {
        if (indexGraph != null) {
            throw new WalkingException("CollectionReference returned an unexpected index graph : " + indexDefinition.getCollectionDefinition().getCollectionPersister().getRole());
        }
    }
}
Also used : Type(org.hibernate.type.Type) CollectionFetchableIndex(org.hibernate.loader.plan.spi.CollectionFetchableIndex) WalkingException(org.hibernate.persister.walking.spi.WalkingException) CollectionReference(org.hibernate.loader.plan.spi.CollectionReference)

Example 4 with WalkingException

use of org.hibernate.persister.walking.spi.WalkingException in project hibernate-orm by hibernate.

the class AbstractLoadPlanBuildingAssociationVisitationStrategy method finishingCollectionElements.

@Override
public void finishingCollectionElements(CollectionElementDefinition elementDefinition) {
    final Type elementType = elementDefinition.getType();
    if (elementType.isAnyType()) {
    // nothing to do because the element graph was not pushed in #startingCollectionElement..
    } else if (elementType.isComponentType() || elementType.isAssociationType()) {
        // pop it from the stack
        final ExpandingFetchSource popped = popFromStack();
        // validation
        if (!CollectionFetchableElement.class.isInstance(popped)) {
            throw new WalkingException("Mismatched FetchSource from stack on pop");
        }
    }
    log.tracef("%s Finished collection element graph : %s", StringHelper.repeat("<<", fetchSourceStack.size()), elementDefinition.getCollectionDefinition().getCollectionPersister().getRole());
}
Also used : Type(org.hibernate.type.Type) ExpandingFetchSource(org.hibernate.loader.plan.build.spi.ExpandingFetchSource) WalkingException(org.hibernate.persister.walking.spi.WalkingException)

Example 5 with WalkingException

use of org.hibernate.persister.walking.spi.WalkingException in project hibernate-orm by hibernate.

the class QuerySpaceHelper method makeCollectionQuerySpace.

public ExpandingCollectionQuerySpace makeCollectionQuerySpace(ExpandingQuerySpace lhsQuerySpace, AssociationAttributeDefinition attributeDefinition, String querySpaceUid, FetchStrategy fetchStrategy) {
    final CollectionType fetchedType = (CollectionType) attributeDefinition.getType();
    final CollectionPersister fetchedPersister = attributeDefinition.toCollectionDefinition().getCollectionPersister();
    if (fetchedPersister == null) {
        throw new WalkingException(String.format("Unable to locate CollectionPersister [%s] for fetch [%s]", fetchedType.getRole(), attributeDefinition.getName()));
    }
    final boolean required = lhsQuerySpace.canJoinsBeRequired() && !attributeDefinition.isNullable();
    final ExpandingCollectionQuerySpace rhs = lhsQuerySpace.getExpandingQuerySpaces().makeCollectionQuerySpace(querySpaceUid, fetchedPersister, required);
    if (shouldIncludeJoin(fetchStrategy)) {
        final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCollectionJoin(lhsQuerySpace, attributeDefinition.getName(), rhs, required, (CollectionType) attributeDefinition.getType(), fetchedPersister.getFactory());
        lhsQuerySpace.addJoin(join);
    }
    return rhs;
}
Also used : CollectionPersister(org.hibernate.persister.collection.CollectionPersister) CollectionType(org.hibernate.type.CollectionType) JoinDefinedByMetadata(org.hibernate.loader.plan.spi.JoinDefinedByMetadata) WalkingException(org.hibernate.persister.walking.spi.WalkingException) ExpandingCollectionQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingCollectionQuerySpace)

Aggregations

WalkingException (org.hibernate.persister.walking.spi.WalkingException)11 ExpandingFetchSource (org.hibernate.loader.plan.build.spi.ExpandingFetchSource)5 Type (org.hibernate.type.Type)5 EntityPersister (org.hibernate.persister.entity.EntityPersister)3 CollectionFetchableIndex (org.hibernate.loader.plan.spi.CollectionFetchableIndex)2 CollectionReference (org.hibernate.loader.plan.spi.CollectionReference)2 EntityReference (org.hibernate.loader.plan.spi.EntityReference)2 AssociationAttributeDefinition (org.hibernate.persister.walking.spi.AssociationAttributeDefinition)2 EntityType (org.hibernate.type.EntityType)2 Iterator (java.util.Iterator)1 HibernateException (org.hibernate.HibernateException)1 FetchStrategy (org.hibernate.engine.FetchStrategy)1 LoadQueryInfluencers (org.hibernate.engine.spi.LoadQueryInfluencers)1 PropertyPath (org.hibernate.loader.PropertyPath)1 ExpandingCollectionQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingCollectionQuerySpace)1 ExpandingEntityIdentifierDescription (org.hibernate.loader.plan.build.spi.ExpandingEntityIdentifierDescription)1 AttributeFetch (org.hibernate.loader.plan.spi.AttributeFetch)1 BidirectionalEntityReference (org.hibernate.loader.plan.spi.BidirectionalEntityReference)1 CollectionAttributeFetch (org.hibernate.loader.plan.spi.CollectionAttributeFetch)1 CompositeAttributeFetch (org.hibernate.loader.plan.spi.CompositeAttributeFetch)1