boolean isSizeProperty = getNextSibling()!=null &&
CollectionProperties.isAnyCollectionProperty( getNextSibling().getText() );
if ( isSizeProperty ) indexed = true; //yuck!
QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection( role );
String propName = getPath();
FromClause currentFromClause = getWalker().getCurrentFromClause();
if ( getWalker().getStatementType() != SqlTokenTypes.SELECT && indexed && classAlias == null ) {
// should indicate that we are processing an INSERT/UPDATE/DELETE
// query with a subquery implied via a collection property
// function. Here, we need to use the table name itself as the
// qualification alias.
// TODO : verify this works for all databases...
// TODO : is this also the case in non-"indexed" scenarios?
String alias = getLhs().getFromElement().getQueryable().getTableName();
columns = getFromElement().toColumns( alias, propertyPath, false, true );
}
//We do not look for an existing join on the same path, because
//it makes sense to join twice on the same collection role
FromElementFactory factory = new FromElementFactory(
currentFromClause,
getLhs().getFromElement(),
propName,
classAlias,
getColumns(),
implicitJoin
);
FromElement elem = factory.createCollection( queryableCollection, role, joinType, fetch, indexed );
if ( log.isDebugEnabled() ) {
log.debug( "dereferenceCollection() : Created new FROM element for " + propName + " : " + elem );
}
setImpliedJoin( elem );
setFromElement( elem ); // This 'dot' expression now refers to the resulting from element.
if ( isSizeProperty ) {
elem.setText("");
elem.setUseWhereFragment(false);
}
if ( !implicitJoin ) {
EntityPersister entityPersister = elem.getEntityPersister();
if ( entityPersister != null ) {
getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );
}
}
getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() ); // Always add the collection's query spaces.
}