String otherSidePropertyName = null;
Loadable elementPersister = (Loadable) collectionPersister.getElementPersister();
Type[] propertyTypes = elementPersister.getPropertyTypes();
for ( int index = 0 ; index < propertyTypes.length ; index++ ) {
Type type = propertyTypes[index];
//we try and restrict type search as much as possible
if ( type.isAssociationType() ) {
boolean matching = false;
//if the main side collection is a one-to-many, the reverse side should be a to-one is not a collection
if ( collectionPersister.isOneToMany() && ! type.isCollectionType() ) {
matching = isToOneMatching( elementPersister, index, type );
}
//if the main side collection is not a one-to-many, the reverse side should be a collection
else if ( ! collectionPersister.isOneToMany() && type.isCollectionType() ) {
matching = isCollectionMatching( (CollectionType) type, collectionPersister.getTableName() );
}
if ( matching ) {
otherSidePropertyName = elementPersister.getPropertyNames()[index];
break;