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