if (hasMappedBy()) {
// Non-owning side, process the foreign keys from the owner.
DatabaseMapping owningMapping = getOwningMapping();
if (owningMapping.isOneToOneMapping()){
OneToOneMapping ownerMapping = (OneToOneMapping) owningMapping;
// If the owner uses a relation table, we need to map the keys
// as we would for a many-to-many mapping.
if (ownerMapping.hasRelationTableMechanism()) {
// Put a relation table mechanism on our mapping.
((OneToOneMapping)mapping).setRelationTableMechanism(new RelationTableMechanism());
processMappedByRelationTable(ownerMapping.getRelationTableMechanism(), ((OneToOneMapping)mapping).getRelationTableMechanism());
} else {
Map<DatabaseField, DatabaseField> targetToSourceKeyFields;
Map<DatabaseField, DatabaseField> sourceToTargetKeyFields;
// If we are within a table per class strategy we have to update
// the primary key field to point to our own database table.
if (getDescriptor().usesTablePerClassInheritanceStrategy()) {
targetToSourceKeyFields = new HashMap<DatabaseField, DatabaseField>();
sourceToTargetKeyFields = new HashMap<DatabaseField, DatabaseField>();
for (DatabaseField fkField : ownerMapping.getSourceToTargetKeyFields().keySet()) {
// We need to update the pk field to be to our table.
DatabaseField pkField = ownerMapping.getSourceToTargetKeyFields().get(fkField).clone();
pkField.setTable(getDescriptor().getPrimaryTable());
sourceToTargetKeyFields.put(fkField, pkField);
targetToSourceKeyFields.put(pkField, fkField);
}
} else {
targetToSourceKeyFields = ownerMapping.getTargetToSourceKeyFields();
sourceToTargetKeyFields = ownerMapping.getSourceToTargetKeyFields();
}
((OneToOneMapping)mapping).setSourceToTargetKeyFields(targetToSourceKeyFields);
((OneToOneMapping)mapping).setTargetToSourceKeyFields(sourceToTargetKeyFields);
}