mapping instanceof SerialisedPCMapping ||
mapping instanceof SerialisedReferenceMapping ||
mapping instanceof PersistableMapping ||
mapping instanceof InterfaceMapping) {
boolean owned = MetaDataUtils.isOwnedRelation(mmd, getStoreManager());
RelationType relationType = mmd.getRelationType(ec.getClassLoaderResolver());
if (owned) {
// Owned relation
boolean owner = false;
if (relationType == RelationType.ONE_TO_ONE_UNI || relationType == RelationType.ONE_TO_MANY_UNI ||
relationType == RelationType.ONE_TO_MANY_BI) {
owner = true;
} else if (relationType == RelationType.ONE_TO_ONE_BI && mmd.getMappedBy() == null) {
owner = true;
}
if (!table.isParentKeyProvider(mmd)) {
// Make sure the parent key is set properly between parent and child objects
if (!owner) {
ObjectProvider parentOP = ec.findObjectProvider(relInfo.value);
EntityUtils.checkParentage(op.getObject(), parentOP);
} else {
EntityUtils.checkParentage(relInfo.value, op);
}
mapping.setObject(ec, datastoreEntity, IS_FK_VALUE_ARR, relInfo.value, op, mmd.getAbsoluteFieldNumber());
}
} else {
// Unowned relation
mapping.setObject(ec, datastoreEntity, IS_FK_VALUE_ARR, relInfo.value, op, mmd.getAbsoluteFieldNumber());
}
}
} catch (NotYetFlushedException e) {
// Ignore this. We always have the object in the datastore, at least partially to get the key
}
}
// Stage 2 : postInsert/postUpdate
for (RelationStoreInformation relInfo : relationStoreInfos) {
try {
JavaTypeMapping mapping = table.getMemberMappingInDatastoreClass(relInfo.mmd);
if (mapping instanceof ArrayMapping || mapping instanceof MapMapping) {
// Ignore postInsert/update for arrays/maps since don't support backing stores
} else if (mapping instanceof MappingCallbacks) {
if (insert) {
((MappingCallbacks)mapping).postInsert(op);
} else {
((MappingCallbacks)mapping).postUpdate(op);
}
}
} catch (NotYetFlushedException e) {
// Ignore this. We always have the object in the datastore, at least partially to get the key
}
}
// Stage 3 : set child keys in parent
for (RelationStoreInformation relInfo : relationStoreInfos) {
AbstractMemberMetaData mmd = relInfo.mmd;
RelationType relationType = mmd.getRelationType(ec.getClassLoaderResolver());
boolean owned = MetaDataUtils.isOwnedRelation(mmd, getStoreManager());
if (owned) {
// Owned relations only store child keys if storageVersion high enough, and at "owner" side.
if (!getStoreManager().storageVersionAtLeast(StorageVersion.WRITE_OWNED_CHILD_KEYS_TO_PARENTS)) {