for (JoinColumnMetadata joinColumn : joinColumns) {
// If the pk field (referencedColumnName) is not specified, it
// defaults to the primary key of the referenced table.
String defaultPKFieldName = descriptor.getPrimaryKeyFieldName();
DatabaseField pkField = joinColumn.getPrimaryKeyField();
pkField.setName(getName(pkField, defaultPKFieldName, PK_CTX));
pkField.setTable(descriptor.getPrimaryKeyTable());
// If the fk field (name) is not specified, it defaults to the
// name of the referencing relationship property or field of the
// referencing entity + "_" + the name of the referenced primary
// key column. If there is no such referencing relationship
// property or field in the entity (i.e., a join table is used),
// the join column name is formed as the concatenation of the
// following: the name of the entity + "_" + the name of the
// referenced primary key column.
DatabaseField fkField = joinColumn.getForeignKeyField();
String defaultFKFieldName = defaultFieldName + "_" + defaultPKFieldName;
fkField.setName(getName(fkField, defaultFKFieldName, FK_CTX));
// Target table name here is the join table name.
// If the user had specified a different table name in the join
// column, it is ignored. Perhaps an error or warning should be
// fired off.
fkField.setTable(mapping.getRelationTable());
// Add a target relation key to the mapping.
if (isSource) {
mapping.addSourceRelationKeyField(fkField, pkField);
} else {