Search in sources :

Example 76 with EntityPersister

use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.

the class StatelessSessionImpl method delete.

@Override
public void delete(String entityName, Object entity) {
    checkOpen();
    EntityPersister persister = getEntityPersister(entityName, entity);
    Serializable id = persister.getIdentifier(entity, this);
    Object version = persister.getVersion(entity);
    persister.delete(id, version, entity, this);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Serializable(java.io.Serializable)

Example 77 with EntityPersister

use of org.hibernate.persister.entity.EntityPersister in project hibernate-orm by hibernate.

the class StatelessSessionImpl method internalLoad.

@Override
public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException {
    checkOpen();
    EntityPersister persister = getFactory().getMetamodel().entityPersister(entityName);
    // first, try to load it from the temp PC associated to this SS
    Object loaded = temporaryPersistenceContext.getEntity(generateEntityKey(id, persister));
    if (loaded != null) {
        // containing eager fetches via join fetch
        return loaded;
    }
    if (!eager && persister.hasProxy()) {
        // generate a proxy
        return persister.createProxy(id, this);
    }
    // otherwise immediately materialize it
    return get(entityName, id);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister)

Example 78 with EntityPersister

use of org.hibernate.persister.entity.EntityPersister 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 79 with EntityPersister

use of org.hibernate.persister.entity.EntityPersister 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 80 with EntityPersister

use of org.hibernate.persister.entity.EntityPersister 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)

Aggregations

EntityPersister (org.hibernate.persister.entity.EntityPersister)166 Test (org.junit.Test)59 Serializable (java.io.Serializable)34 Session (org.hibernate.Session)31 Type (org.hibernate.type.Type)29 EntityEntry (org.hibernate.engine.spi.EntityEntry)21 EventSource (org.hibernate.event.spi.EventSource)15 EntityRegionAccessStrategy (org.hibernate.cache.spi.access.EntityRegionAccessStrategy)13 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)13 TestForIssue (org.hibernate.testing.TestForIssue)13 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)12 SequenceStyleGenerator (org.hibernate.id.enhanced.SequenceStyleGenerator)12 EntityType (org.hibernate.type.EntityType)12 ArrayList (java.util.ArrayList)11 CompositeType (org.hibernate.type.CompositeType)11 HibernateProxy (org.hibernate.proxy.HibernateProxy)10 PreparedStatement (java.sql.PreparedStatement)8 List (java.util.List)8 EntityKey (org.hibernate.engine.spi.EntityKey)8 QueryParameters (org.hibernate.engine.spi.QueryParameters)8