@Override
public void process() {
super.process();
// Initialize our mapping now with what we found.
OneToOneMapping mapping = initOneToOneMapping();
if (hasMappedBy()) {
// Non-owning side, process the foreign keys from the owner.
DatabaseMapping owningMapping = getOwningMappingAccessor();
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.
mapping.setRelationTableMechanism(new RelationTableMechanism());
processMappedByRelationTable(ownerMapping.getRelationTableMechanism(), 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();
}
mapping.setSourceToTargetKeyFields(targetToSourceKeyFields);
mapping.setTargetToSourceKeyFields(sourceToTargetKeyFields);
}