protected function setEmbeds(Metadata\Interfaces\EmbedInterface $metadata, array $embedMapping)
    {
        foreach ($embedMapping as $key => $mapping) {
            if (!is_array($mapping)) {
                $mapping = ['type' => null, 'entity' => null];
            }

            if (!isset($mapping['type'])) {
                $mapping['type'] = null;
            }

            if (!isset($mapping['entity'])) {
                $mapping['entity'] = null;
            }

            if ($metadata instanceof Metadata\EmbedMetadata && $mapping['entity'] === $metadata->name) {
                // This embed meta is referencing itself as an embed property. As such, do not recreate.
                // This prevents infinite recursion.
                $embedMeta = $metadata;
            } else {
                $embedMeta = $this->loadMetadataForEmbed($mapping['entity']);
            }
            if (null === $embedMeta) {
                continue;
            }
            $property = new Metadata\EmbeddedPropMetadata($key, $mapping['type'], $embedMeta, $this->isMixin($metadata));

            if (isset($mapping['serialize'])) {
                $property->enableSerialize($mapping['serialize']);
            }

            $metadata->addEmbed($property);
        }
        return $metadata;
    }