// temporary map used later to write fk fields in special order
Map fkFieldsByRelatedPKFields = new HashMap();
for(Iterator i = foreignKeys.iterator(); i.hasNext();)
{
JDBCCMPFieldMetaData fkFieldMetaData = (JDBCCMPFieldMetaData)i.next();
JDBCCMPFieldBridge2 relatedPKField =
(JDBCCMPFieldBridge2)relatedEntity.getFieldByName(fkFieldMetaData.getFieldName());
// now determine whether the fk is mapped to a pk column
String fkColumnName = fkFieldMetaData.getColumnName();
JDBCCMPFieldBridge2 fkField = null;
// look among the CMP fields for the field with the same column name
JDBCCMPFieldBridge2[] tableFields = (JDBCCMPFieldBridge2[])entity.getTableFields();
for(int tableInd = 0; tableInd < tableFields.length && fkField == null; ++tableInd)