WebfactoryPolyglotBundle 使用导致错误"No mapping found for field 'id' on class 'AppBundle\Entity\Film'."

WebfactoryPolyglotBundle use causes error "No mapping found for field 'id' on class 'AppBundle\Entity\Film'."

我使用 Symfony 版本 3.4.0,我尝试使用这个包来翻译实体:https://github.com/webfactory/WebfactoryPolyglotBundle

所以我为测试创建了两个实体(Film 和 FilmTranslation)

这是我的Film.php

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use Webfactory\Bundle\PolyglotBundle\Annotation as Polyglot;
use Webfactory\Bundle\PolyglotBundle\TranslatableInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Film
 *
 * @ORM\Table(name="film")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\FilmRepository")
 * @Polyglot\Locale(primary="fr_FR")
 */
class Film
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @Polyglot\TranslationCollection
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="Titre", type="string", length=255, unique=true)
     * @Polyglot\Translatable
     * @var string|TranslatableInterface
     */
    private $titre;

    /**
     * @ORM\OneToMany(targetEntity="FilmTranslation", mappedBy="entity")
     * @Polyglot\TranslationCollection
     * @var Collection
     */
    private $translations;

    public function __construct()
    {
        $this->translations = new ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set titre
     *
     * @param string $titre
     *
     * @return Film
     */
    public function setTitre($titre)
    {
        $this->titre = $titre;

        return $this;
    }

    /**
     * Get titre
     *
     * @return string
     */
    public function getTitre()
    {
        return $this->titre;
    }

    /**
     * Add translation
     *
     * @param \AppBundle\Entity\FilmTranslation $translation
     *
     * @return Film
     */
    public function addTranslation(\AppBundle\Entity\FilmTranslation $translation)
    {
        $this->translations[] = $translation;

        return $this;
    }

    /**
     * Remove translation
     *
     * @param \AppBundle\Entity\FilmTranslation $translation
     */
    public function removeTranslation(\AppBundle\Entity\FilmTranslation $translation)
    {
        $this->translations->removeElement($translation);
    }

    /**
     * Get translations
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getTranslations()
    {
        return $this->translations;
    }
}

这是我的 FilmTranslation.php

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Webfactory\Bundle\PolyglotBundle\Entity\BaseTranslation;

/**
 * FilmTranslation
 *
 * @ORM\Table(name="film_translation")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\FilmTranslationRepository")
 * @ORM\Table(
 *      uniqueConstraints = {
 *          @ORM\UniqueConstraint(columns={"entity_id", "locale"})
 *     }
 * )
 */
class FilmTranslation extends BaseTranslation
{

    /**
     * @var string
     *
     * @ORM\Column(name="titre", type="string", length=255, unique=true)
     */
    private $titre;

    /**
     * @ORM\ManyToOne(targetEntity="Film", inversedBy="translations")
     * @var Film
     */
    protected $entity;

    /**
     * Set titre
     *
     * @param string $titre
     *
     * @return FilmTranslation
     */
    public function setTitre($titre)
    {
        $this->titre = $titre;

        return $this;
    }

    /**
     * Get titre
     *
     * @return string
     */
    public function getTitre()
    {
        return $this->titre;
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set locale
     *
     * @param string $locale
     *
     * @return FilmTranslation
     */
    public function setLocale($locale)
    {
        $this->locale = $locale;

        return $this;
    }

    /**
     * Set entity
     *
     * @param \AppBundle\Entity\Film $entity
     *
     * @return FilmTranslation
     */
    public function setEntity(\AppBundle\Entity\Film $entity = null)
    {
        $this->entity = $entity;

        return $this;
    }

    /**
     * Get entity
     *
     * @return \AppBundle\Entity\Film
     */
    public function getEntity()
    {
        return $this->entity;
    }
}

我可以创建一个表单,但是当我尝试坚持并刷新时,出现以下错误:

No mapping found for field 'id' on class 'AppBundle\Entity\Film'.

我做错了什么吗?

所以像这样从 $id 注释中删除 @Polyglot\TranslationCollection ;)

class Film
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;