public function checkOverwrite(array $entities, $allowOverwrite = false)
    {
        $this->validateBatch($entities, EntityInterface::class);

        foreach ($entities as $entity) {
            if (!$entity->populatedByService() && !$allowOverwrite) {
                throw new \InvalidArgumentException(sprintf(
                    'Given entity cannot be saved because it may overwrite an '.
                    'existing record. When updating manually created entities, '.
                    'please set the options `$allowOverwrite` flag to `true`. '.
                    'Invalid entity key was %s',
                    (string) $entity->key()
                ));
            }
        }
    }