if ( type.isAssociationType() ) {
// we build the association-key here because of the "goofiness" with 'currentColumnPosition'
final AssociationKey associationKey;
final AssociationType aType = (AssociationType) type;
final Joinable joinable = aType.getAssociatedJoinable( sessionFactory() );
if ( aType.isAnyType() ) {
associationKey = new AssociationKey(
JoinHelper.getLHSTableName(
aType,
attributeNumber(),
(OuterJoinLoadable) locateOwningPersister()
),
JoinHelper.getLHSColumnNames(
aType,
attributeNumber(),
columnPosition,
(OuterJoinLoadable) locateOwningPersister(),
sessionFactory()
)
);
}
else if ( aType.getForeignKeyDirection() == ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT ) {
final String lhsTableName;
final String[] lhsColumnNames;
if ( joinable.isCollection() ) {
final QueryableCollection collectionPersister = (QueryableCollection) joinable;
lhsTableName = collectionPersister.getTableName();
lhsColumnNames = collectionPersister.getElementColumnNames();
}
else {
final OuterJoinLoadable entityPersister = (OuterJoinLoadable) locateOwningPersister();
lhsTableName = getLHSTableName( aType, attributeNumber(), entityPersister );
lhsColumnNames = getLHSColumnNames(
aType,
attributeNumber(),
columnPosition,
entityPersister,
sessionFactory()
);
}
associationKey = new AssociationKey( lhsTableName, lhsColumnNames );
}
else {
associationKey = new AssociationKey(
joinable.getTableName(),
getRHSColumnNames( aType, sessionFactory() )
);
}
final CompositeType cType = getType();