if(manyToMany) {
ManyToOne element = new ManyToOne( collection.getCollectionTable() );
//TODO: find the other foreignkey and choose the other side.
Iterator foreignKeyIterator = foreignKey.getTable().getForeignKeyIterator();
List keys = new ArrayList();
while ( foreignKeyIterator.hasNext() ) {
Object next = foreignKeyIterator.next();
if(next!=foreignKey) {
keys.add(next);
}
}
if(keys.size()>1) {
throw new JDBCBinderException("more than one other foreign key to choose from!"); // todo: handle better ?
}
ForeignKey fk = (ForeignKey) keys.get( 0 );
String tableToClassName = bindCollection( rc, foreignKey, fk, collection );
element.setReferencedEntityName( tableToClassName );
element.addColumn( fk.getColumn( 0 ) );
collection.setElement( element );
} else {
String tableToClassName = bindCollection( rc, foreignKey, null, collection );