use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.
the class LoadQueryJoinAndFetchProcessor method renderCollectionJoin.
private void renderCollectionJoin(Join join, JoinFragment joinFragment) {
final CollectionQuerySpace rightHandSide = (CollectionQuerySpace) join.getRightHandSide();
// The SQL join to the "collection table" needs to be rendered.
//
// In the case of a basic collection, that's the only join needed.
//
// For one-to-many/many-to-many, we need to render the "collection table join"
// here (as already stated). There will be a follow-on join (rhs will have a join) for the associated entity.
// For many-to-many, the follow-on join will join to the associated entity element table. For one-to-many,
// the collection table is the associated entity table, so the follow-on join will not be rendered..
// currently we do not explicitly track the joins under the CollectionQuerySpace to know which is
// the element join and which is the index join (maybe we should?).
JoinDefinedByMetadata collectionElementJoin = null;
JoinDefinedByMetadata collectionIndexJoin = null;
for (Join collectionJoin : rightHandSide.getJoins()) {
if (JoinDefinedByMetadata.class.isInstance(collectionJoin)) {
final JoinDefinedByMetadata collectionJoinDefinedByMetadata = (JoinDefinedByMetadata) collectionJoin;
if (CollectionPropertyNames.COLLECTION_ELEMENTS.equals(collectionJoinDefinedByMetadata.getJoinedPropertyName())) {
if (collectionElementJoin != null) {
throw new AssertionFailure(String.format("More than one element join defined for: %s", rightHandSide.getCollectionPersister().getRole()));
}
collectionElementJoin = collectionJoinDefinedByMetadata;
}
if (CollectionPropertyNames.COLLECTION_INDICES.equals(collectionJoinDefinedByMetadata.getJoinedPropertyName())) {
if (collectionIndexJoin != null) {
throw new AssertionFailure(String.format("More than one index join defined for: %s", rightHandSide.getCollectionPersister().getRole()));
}
collectionIndexJoin = collectionJoinDefinedByMetadata;
}
}
}
if (rightHandSide.getCollectionPersister().isOneToMany() || rightHandSide.getCollectionPersister().isManyToMany()) {
// sql aliases to use for the entity.
if (collectionElementJoin == null) {
throw new IllegalStateException(String.format("Could not locate collection element join within collection join [%s : %s]", rightHandSide.getUid(), rightHandSide.getCollectionPersister()));
}
aliasResolutionContext.generateCollectionReferenceAliases(rightHandSide.getUid(), rightHandSide.getCollectionPersister(), collectionElementJoin.getRightHandSide().getUid());
} else {
aliasResolutionContext.generateCollectionReferenceAliases(rightHandSide.getUid(), rightHandSide.getCollectionPersister(), null);
}
if (rightHandSide.getCollectionPersister().hasIndex() && rightHandSide.getCollectionPersister().getIndexType().isEntityType()) {
// sql aliases to use for the entity.
if (collectionIndexJoin == null) {
throw new IllegalStateException(String.format("Could not locate collection index join within collection join [%s : %s]", rightHandSide.getUid(), rightHandSide.getCollectionPersister()));
}
aliasResolutionContext.generateEntityReferenceAliases(collectionIndexJoin.getRightHandSide().getUid(), rightHandSide.getCollectionPersister().getIndexDefinition().toEntityDefinition().getEntityPersister());
}
addJoins(join, joinFragment, (Joinable) rightHandSide.getCollectionPersister(), null);
}
Aggregations