Search in sources :

Example 6 with EntityType

use of org.hibernate.type.EntityType in project hibernate-orm by hibernate.

the class AbstractCollectionReference method buildElementGraph.

private CollectionFetchableElement buildElementGraph() {
    final CollectionPersister persister = collectionQuerySpace.getCollectionPersister();
    final Type type = persister.getElementType();
    if (type.isAssociationType()) {
        if (type.isEntityType()) {
            final EntityPersister elementPersister = persister.getFactory().getEntityPersister(((EntityType) type).getAssociatedEntityName());
            final ExpandingEntityQuerySpace entityQuerySpace = QuerySpaceHelper.INSTANCE.makeEntityQuerySpace(collectionQuerySpace, elementPersister, CollectionPropertyNames.COLLECTION_ELEMENTS, (EntityType) persister.getElementType(), collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(), collectionQuerySpace.canJoinsBeRequired(), allowElementJoin);
            return new CollectionFetchableElementEntityGraph(this, entityQuerySpace);
        } else if (type.isAnyType()) {
            return new CollectionFetchableElementAnyGraph(this);
        }
    } else if (type.isComponentType()) {
        final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace(collectionQuerySpace, new CompositePropertyMapping((CompositeType) persister.getElementType(), (PropertyMapping) persister, ""), CollectionPropertyNames.COLLECTION_ELEMENTS, (CompositeType) persister.getElementType(), collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(), collectionQuerySpace.canJoinsBeRequired(), allowElementJoin);
        return new CollectionFetchableElementCompositeGraph(this, compositeQuerySpace);
    }
    return null;
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) ExpandingCompositeQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace) EntityType(org.hibernate.type.EntityType) CompositeType(org.hibernate.type.CompositeType) Type(org.hibernate.type.Type) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) CompositePropertyMapping(org.hibernate.loader.plan.build.internal.spaces.CompositePropertyMapping) ExpandingEntityQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingEntityQuerySpace) CompositeType(org.hibernate.type.CompositeType)

Example 7 with EntityType

use of org.hibernate.type.EntityType 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 8 with EntityType

use of org.hibernate.type.EntityType in project hibernate-orm by hibernate.

the class SQLQueryReturnProcessor method processJoinReturn.

private void processJoinReturn(NativeSQLQueryJoinReturn fetchReturn) {
    String alias = fetchReturn.getAlias();
    //		if ( alias2Persister.containsKey( alias ) || collectionAliases.contains( alias ) ) {
    if (alias2Persister.containsKey(alias) || alias2CollectionPersister.containsKey(alias)) {
        // already been processed...
        return;
    }
    String ownerAlias = fetchReturn.getOwnerAlias();
    // Make sure the owner alias is known...
    if (!alias2Return.containsKey(ownerAlias)) {
        throw new HibernateException("Owner alias [" + ownerAlias + "] is unknown for alias [" + alias + "]");
    }
    // If this return's alias has not been processed yet, do so b4 further processing of this return
    if (!alias2Persister.containsKey(ownerAlias)) {
        NativeSQLQueryNonScalarReturn ownerReturn = (NativeSQLQueryNonScalarReturn) alias2Return.get(ownerAlias);
        processReturn(ownerReturn);
    }
    SQLLoadable ownerPersister = (SQLLoadable) alias2Persister.get(ownerAlias);
    Type returnType = ownerPersister.getPropertyType(fetchReturn.getOwnerProperty());
    if (returnType.isCollectionType()) {
        String role = ownerPersister.getEntityName() + '.' + fetchReturn.getOwnerProperty();
        addCollection(role, alias, fetchReturn.getPropertyResultsMap());
    //			collectionOwnerAliases.add( ownerAlias );
    } else if (returnType.isEntityType()) {
        EntityType eType = (EntityType) returnType;
        String returnEntityName = eType.getAssociatedEntityName();
        SQLLoadable persister = getSQLLoadable(returnEntityName);
        addPersister(alias, fetchReturn.getPropertyResultsMap(), persister);
    }
}
Also used : EntityType(org.hibernate.type.EntityType) NativeSQLQueryNonScalarReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryNonScalarReturn) EntityType(org.hibernate.type.EntityType) Type(org.hibernate.type.Type) HibernateException(org.hibernate.HibernateException) SQLLoadable(org.hibernate.persister.entity.SQLLoadable)

Example 9 with EntityType

use of org.hibernate.type.EntityType in project hibernate-orm by hibernate.

the class QuerySpaceHelper method makeEntityQuerySpace.

public ExpandingEntityQuerySpace makeEntityQuerySpace(ExpandingQuerySpace lhsQuerySpace, AssociationAttributeDefinition attribute, String querySpaceUid, FetchStrategy fetchStrategy) {
    final EntityType fetchedType = (EntityType) attribute.getType();
    final EntityPersister fetchedPersister = attribute.toEntityDefinition().getEntityPersister();
    if (fetchedPersister == null) {
        throw new WalkingException(String.format("Unable to locate EntityPersister [%s] for fetch [%s]", fetchedType.getAssociatedEntityName(), attribute.getName()));
    }
    // TODO: Queryable.isMultiTable() may be more broad than it needs to be...
    final boolean isMultiTable = Queryable.class.cast(fetchedPersister).isMultiTable();
    final boolean required = lhsQuerySpace.canJoinsBeRequired() && !isMultiTable && !attribute.isNullable();
    return makeEntityQuerySpace(lhsQuerySpace, fetchedPersister, attribute.getName(), (EntityType) attribute.getType(), querySpaceUid, required, shouldIncludeJoin(fetchStrategy));
}
Also used : EntityType(org.hibernate.type.EntityType) EntityPersister(org.hibernate.persister.entity.EntityPersister) Queryable(org.hibernate.persister.entity.Queryable) WalkingException(org.hibernate.persister.walking.spi.WalkingException)

Example 10 with EntityType

use of org.hibernate.type.EntityType in project hibernate-orm by hibernate.

the class EntityReferenceInitializerImpl method handleMissingIdentifier.

private void handleMissingIdentifier(ResultSetProcessingContext context) {
    if (EntityFetch.class.isInstance(entityReference)) {
        final EntityFetch fetch = (EntityFetch) entityReference;
        final EntityType fetchedType = fetch.getFetchedType();
        if (!fetchedType.isOneToOne()) {
            return;
        }
        final EntityReferenceProcessingState fetchOwnerState = context.getOwnerProcessingState(fetch);
        if (fetchOwnerState == null) {
            throw new IllegalStateException("Could not locate fetch owner state");
        }
        final EntityKey ownerEntityKey = fetchOwnerState.getEntityKey();
        if (ownerEntityKey != null) {
            context.getSession().getPersistenceContext().addNullProperty(ownerEntityKey, fetchedType.getPropertyName());
        }
    }
}
Also used : EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) EntityType(org.hibernate.type.EntityType) EntityKey(org.hibernate.engine.spi.EntityKey) EntityReferenceProcessingState(org.hibernate.loader.plan.exec.process.spi.ResultSetProcessingContext.EntityReferenceProcessingState)

Aggregations

EntityType (org.hibernate.type.EntityType)28 Type (org.hibernate.type.Type)18 EntityPersister (org.hibernate.persister.entity.EntityPersister)9 JoinSequence (org.hibernate.engine.internal.JoinSequence)6 JoinType (org.hibernate.sql.JoinType)6 CompositeType (org.hibernate.type.CompositeType)6 AssociationType (org.hibernate.type.AssociationType)5 CollectionType (org.hibernate.type.CollectionType)5 QueryException (org.hibernate.QueryException)4 Queryable (org.hibernate.persister.entity.Queryable)4 MappingException (org.hibernate.MappingException)3 EntityKey (org.hibernate.engine.spi.EntityKey)3 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)3 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2