if (ownerMemberMetaData.getRelationType(clr) == Relation.ONE_TO_MANY_BI &&
sm.getObjectManager().getOMFContext().getPersistenceConfiguration().getBooleanProperty("org.jpox.manageRelationships"))
{
// Managed Relations : make sure we have consistency of relation
StateManager elementSM = sm.getObjectManager().findStateManager(element);
if (elementSM != null)
{
AbstractMemberMetaData[] relatedMmds = ownerMemberMetaData.getRelatedMemberMetaData(clr);
Object elementOwner = elementSM.provideField(relatedMmds[0].getAbsoluteFieldNumber());
if (elementOwner == null)
{
// No owner, so correct it
JPOXLogger.JDO.info(LOCALISER.msg("056037",
StringUtils.toJVMIDString(sm.getObject()), ownerMemberMetaData.getFullFieldName(),
StringUtils.toJVMIDString(elementSM.getObject())));
elementSM.replaceField(relatedMmds[0].getAbsoluteFieldNumber(), sm.getObject(), false);
}
else if (elementOwner != sm.getObject() && sm.getReferencedPC() == null)
{
// Owner of the element is neither this container nor its referenced object
// Inconsistent owner, so throw exception
throw new JPOXUserException(LOCALISER.msg("056038",
StringUtils.toJVMIDString(sm.getObject()), ownerMemberMetaData.getFullFieldName(),
StringUtils.toJVMIDString(elementSM.getObject()),
StringUtils.toJVMIDString(elementOwner)));
}
}
}
}