if (elem.getTypeCode() != JavaTypes.PC || elem.isEmbeddedPC()
|| !elem.getTypeMapping().isMapped())
throw new MetaDataException(_loc.get("not-elem-relation", field));
// check for named inverse
FieldMappingInfo finfo = field.getMappingInfo();
ValueMappingInfo vinfo = elem.getValueInfo();
boolean criteria = vinfo.getUseClassCriteria();
if (mapped != null) {
mapped.resolve(mapped.MODE_META | mapped.MODE_MAPPING);
if (!(mapped.getStrategy() instanceof RelationFieldStrategy
|| mapped.getHandler() instanceof UntypedPCValueHandler))
throw new MetaDataException(_loc.get("not-inv-relation",
field, mapped));
vinfo.assertNoSchemaComponents(elem, !adapt);
elem.setForeignKey(mapped.getForeignKey
(field.getDefiningMapping()));
elem.setColumns(mapped.getDefiningMapping().
getPrimaryKeyColumns());
elem.setJoinDirection(ValueMapping.JOIN_EXPECTED_INVERSE);
elem.setUseClassCriteria(criteria);
ForeignKey fk = mapped.getForeignKey();
/** Foreign key may be null if declared type of the mapped field is
* abstract and under table-per-class inheritance strategy will have
* no mapped table.
*/
if (fk != null) {
field.setOrderColumn(finfo.getOrderColumn(field,
fk.getTable(), adapt));
field.setOrderColumnIO(finfo.getColumnIO());
}
return;
} else {
if (field.getValueInfo().getColumns().size() > 0 &&
field.getAccessType() == FieldMetaData.ONE_TO_MANY) {
_uni1MFK = true;
}
}
// map inverse foreign key in related table
ForeignKey fk = vinfo.getInverseTypeJoin(elem, field.getName(), adapt);
if (_uni1MFK) {
Column[] locals = fk.getColumns();
for (int i = 0; i < locals.length; i++)
locals[i].setUni1MFK(true);
}
elem.setForeignKey(fk);
elem.setColumnIO(vinfo.getColumnIO());
elem.setColumns(elem.getTypeMapping().getPrimaryKeyColumns());
elem.setJoinDirection(ValueMapping.JOIN_EXPECTED_INVERSE);
elem.setUseClassCriteria(criteria);
elem.mapConstraints(field.getName(), adapt);
field.setOrderColumn(finfo.getOrderColumn(field, fk.getTable(),
adapt));
field.setOrderColumnIO(finfo.getColumnIO());
}