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