for (Object instance : sessionContext.getRelationCache().writtenInstances()) {
Relation relation = sessionContext.getRelationInstanceManager().getDatastoreType(instance);
instanceListenerService.preUpdate(instance);
validateInstance(instance);
datastoreSession.flushRelation(relation);
instanceListenerService.postUpdate(instance);
}
for (Object instance : sessionContext.getEntityCache().writtenInstances()) {
Entity entity = sessionContext.getEntityInstanceManager().getDatastoreType(instance);
instanceListenerService.preUpdate(instance);
validateInstance(instance);