use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.
the class FromElementType method getJoinSequence.
public JoinSequence getJoinSequence() {
if (joinSequence != null) {
return joinSequence;
}
// Class names in the FROM clause result in a JoinSequence (the old FromParser does this).
if (persister instanceof Joinable) {
Joinable joinable = (Joinable) persister;
final JoinSequence joinSequence = fromElement.getSessionFactoryHelper().createJoinSequence().setRoot(joinable, getTableAlias());
joinSequence.applyTreatAsDeclarations(treatAsDeclarations);
return joinSequence;
} else {
// TODO: Should this really return null? If not, figure out something better to do here.
return null;
}
}
use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.
the class AbstractLoadPlanBuildingAssociationVisitationStrategy method foundCircularAssociation.
@Override
public void foundCircularAssociation(AssociationAttributeDefinition attributeDefinition) {
final FetchStrategy fetchStrategy = determineFetchStrategy(attributeDefinition);
if (fetchStrategy.getStyle() != FetchStyle.JOIN) {
// nothing to do
return;
}
final AssociationKey associationKey = attributeDefinition.getAssociationKey();
// go ahead and build the bidirectional fetch
if (attributeDefinition.getAssociationNature() == AssociationAttributeDefinition.AssociationNature.ENTITY) {
final Joinable currentEntityPersister = (Joinable) currentSource().resolveEntityReference().getEntityPersister();
final AssociationKey currentEntityReferenceAssociationKey = new AssociationKey(currentEntityPersister.getTableName(), currentEntityPersister.getKeyColumnNames());
// if associationKey is equal to currentEntityReferenceAssociationKey
// that means that the current EntityPersister has a single primary key attribute
// (i.e., derived attribute) which is mapped by attributeDefinition.
// This is not a bidirectional association.
// TODO: AFAICT, to avoid an overflow, the associated entity must already be loaded into the session, or
// it must be loaded when the ID for the dependent entity is resolved. Is there some other way to
// deal with this???
final FetchSource registeredFetchSource = registeredFetchSource(associationKey);
if (registeredFetchSource != null && !associationKey.equals(currentEntityReferenceAssociationKey)) {
currentSource().buildBidirectionalEntityReference(attributeDefinition, fetchStrategy, registeredFetchSource(associationKey).resolveEntityReference());
}
} else {
// Do nothing for collection
}
}
use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.
the class AbstractLoadPlanBuildingAssociationVisitationStrategy method startingCollection.
@Override
public void startingCollection(CollectionDefinition collectionDefinition) {
// see if the EntityDefinition is a root...
final boolean isRoot = fetchSourceStack.isEmpty();
if (!isRoot) {
// if not, this call should represent a fetch which should have been handled in #startingAttribute
return;
}
log.tracef("%s Starting root collection : %s", StringHelper.repeat(">>", fetchSourceStack.size()), collectionDefinition.getCollectionPersister().getRole());
// if we get here, it is a root
if (!supportsRootCollectionReturns()) {
throw new HibernateException("This strategy does not support root collection returns");
}
final CollectionReturn collectionReturn = new CollectionReturnImpl(collectionDefinition, querySpaces);
pushToCollectionStack(collectionReturn);
addRootReturn(collectionReturn);
associationKeyRegistered(new AssociationKey(((Joinable) collectionDefinition.getCollectionPersister()).getTableName(), ((Joinable) collectionDefinition.getCollectionPersister()).getKeyColumnNames()));
}
use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.
the class EntityLoadQueryDetails method applyRootReturnWhereJoinRestrictions.
protected void applyRootReturnWhereJoinRestrictions(SelectStatementBuilder selectStatementBuilder) {
final Joinable joinable = (OuterJoinLoadable) getRootEntityReturn().getEntityPersister();
selectStatementBuilder.appendRestrictions(joinable.whereJoinFragment(entityReferenceAliases.getTableAlias(), true, true));
}
use of org.hibernate.persister.entity.Joinable in project hibernate-orm by hibernate.
the class JoinWalker method addAssociationToJoinTree.
/**
* Add on association (one-to-one, many-to-one, or a collection) to a list
* of associations to be fetched by outerjoin
*/
private void addAssociationToJoinTree(final AssociationType type, final String[] aliasedLhsColumns, final String alias, final PropertyPath path, final int currentDepth, final JoinType joinType) throws MappingException {
Joinable joinable = type.getAssociatedJoinable(getFactory());
// important to generate alias based on size of association collection
// *before* adding this join to that collection
String subalias = generateTableAlias(associations.size() + 1, path, joinable);
// NOTE : it should be fine to continue to pass only filters below
// (instead of LoadQueryInfluencers) since "from that point on" we
// only need to worry about restrictions (and not say adding more
// joins)
OuterJoinableAssociation assoc = new OuterJoinableAssociation(path, type, alias, aliasedLhsColumns, subalias, joinType, joinable.consumesEntityAlias() ? getWithClause(path) : "", hasRestriction(path), getFactory(), loadQueryInfluencers.getEnabledFilters());
assoc.validateJoin(path.getFullPath());
associations.add(assoc);
int nextDepth = currentDepth + 1;
// path = "";
if (!joinable.isCollection()) {
if (joinable instanceof OuterJoinLoadable) {
walkEntityTree((OuterJoinLoadable) joinable, subalias, path, nextDepth);
}
} else {
if (joinable instanceof QueryableCollection) {
walkCollectionTree((QueryableCollection) joinable, subalias, path, nextDepth);
}
}
}
Aggregations