Get unsaved node from route parameter
With the help from @Clive I found a solution:

/**
 * Implements hook_node_update().
 */
function MY_MODULE_node_update(\Drupal\node\NodeInterface $node) {
  foreach ($node-&gt;getFieldDefinitions() as $definition) {
    if (!in_array($definition-&gt;getType(), ['entity_reference', 'entity_reference_revisions'])) {
      continue;
    }
    if (!$definition-&gt;getSetting('target_type')) {
      continue;
    }
    if ($definition-&gt;getSetting('target_type') == 'media') {
      $media = $node-&gt;{$definition-&gt;getName()}-&gt;entity;
      if ($media) {
        $media-&gt;groups-&gt;target_id = $node-&gt;groups-&gt;target_id;
        $media-&gt;save();
      }
    }
    if ($definition-&gt;getSetting('target_type') == 'paragraph') {
      $paragraph = $node-&gt;{$definition-&gt;getName()}-&gt;entity;
      if ($paragraph) {
        MY_MODULE_update_media_items($paragraph, $node-&gt;groups);
      }
    }
  }
}

/**
 * Set groups on all media items referenced in a paragraph.
 *
 * @param $paragraph
 *   The paragraph.
 * @param $groups
 *   The groups to set.
 */
function MY_MODULE_update_media_items($paragraph, $groups) {
  foreach ($paragraph-&gt;getFieldDefinitions() as $definition) {
    if (!in_array($definition-&gt;getType(), ['entity_reference', 'entity_reference_revisions'])) {
      continue;
    }
    if (!$definition-&gt;getSetting('target_type')) {
      continue;
    }
    if ($definition-&gt;getSetting('target_type') == 'media') {
      $media = $paragraph-&gt;{$definition-&gt;getName()}-&gt;entity;
      if ($media) {
        $media-&gt;groups-&gt;target_id = $groups-&gt;target_id;
        $media-&gt;save();
      }
    }
    if ($definition-&gt;getSetting('target_type') == 'paragraph') {
      $paragraph = $paragraph-&gt;{$definition-&gt;getName()}-&gt;entity;
      if ($paragraph) {
        MY_MODULE_update_media_items($paragraph, $groups);
      }
    }
  }
}