title: Symfony3 Edit Entity : Error Missing value for primary key
body: <p>I try to create a tree structure for a catalog of products.
  A catalog can have multiple levels and levels can contain multiple products.</p>
  
  <p>I manage to save my structure in database but when I want to edit it, I have this error :</p>
  
  <pre><code>Error : Missing value for primary key catalogCode on AppBundle\Entity\CatalogLevel
  at OutOfBoundsException ::missingPrimaryKeyValue ('AppBundle\Entity\CatalogLevel', 'catalogCode')
  in vendor\doctrine\common\lib\Doctrine\Common\Proxy\AbstractProxyFactory.php at line 125
  </code></pre>
  
  <p>when I do this in my CatalogController :</p>
  
  <pre><code>$form = $this-&gt;createForm(CatalogTreeType::class, $catalog);
  </code></pre>
  
  <p>But, just before that line, I verify if I get my levels correctly and it's looking like that's the case :</p>
  
  <pre><code>// Create an ArrayCollection of the current levels
  $originalLevels = new ArrayCollection();
  foreach ($catalog-&gt;getLevels() as $level) {
     var_dump($level-&gt;getCatalogCode());
     $originalLevels-&gt;add($level);
  }
  
  // returns
  AppBundle\Controller\CatalogController.php:337:string 'TT-FTEST' (length=8)
  
  AppBundle\Controller\CatalogController.php:337:string 'TT-FTEST' (length=8)
  </code></pre>
  
  <p><code>CatalogLevel</code> entity has a composite key : levelId + catalogCode.</p>
  
  <p>Considering the primary key <code>catalogCode</code> <strong>isn't empty</strong>, I don't understand this error...</p>
  
  <p><strong>Catalog Entity</strong></p>
  
  <pre><code>/**
   * @ORM\Table(name="catalogue")
   * @ORM\Entity(repositoryClass="AppBundle\Entity\CatalogRepository")
   * @UniqueEntity(fields="code", message="Catalog code already exists")
   */
  class Catalog
  {
      /**
       * @ORM\Column(name="Catalogue_Code", type="string", length=15)
       * @ORM\Id
       * @Assert\NotBlank()
       * @Assert\Length(max=15, maxMessage="The code is too long ({{ limit }} characters max)")
       */
      private $code;
  
      /**
       * @ORM\OneToMany(targetEntity="CatalogLevel", mappedBy="catalog", cascade={"persist", "remove"})
       * @Assert\Valid
       */
      private $levels;
  
      /**
       * Constructor
       */
      public function __construct()
      {
          $this-&gt;levels = new ArrayCollection();
      }
  
      /**
       * Get levels
       *
       * @return ArrayCollection
       */
      public function getLevels()
      {
        return $this-&gt;levels;
      }
  
      /**
       * Add level
       *
       * @param \AppBundle\Entity\CatalogLevel $level
       *
       * @return Catalog
       */
      public function addLevel(\AppBundle\Entity\CatalogLevel $level)
      {
          $level-&gt;setCatalogCode($this-&gt;getCode());
          $level-&gt;setCatalog($this);
  
          if (!$this-&gt;getLevels()-&gt;contains($level)) {
              $this-&gt;levels-&gt;add($level);
          }
  
          return $this;
      }
  
      /**
       * Remove level
       *
       * @param \AppBundle\Entity\CatalogLevel $level
       */
     public function removeLevel(\AppBundle\Entity\CatalogLevel $level)
      {
          $this-&gt;levels-&gt;removeElement($level);
      }
  }
  </code></pre>
  
  <p><strong>CatalogLevel Entity</strong></p>
  
  <pre><code>/**
   * @ORM\Table(name="catalogue_niveau")
   * @ORM\Entity(repositoryClass="AppBundle\Entity\CatalogLevelRepository")
   */
  class CatalogLevel
  {
      /**
       * @ORM\Column(name="Niveau_ID", type="string", length=15)
       * @ORM\Id
       */
      private $id;
  
      /**
       * @ORM\Column(name="Catalogue_Code", type="string", length=15)
       * @ORM\Id
       */
      private $catalogCode;
  
      /**
       * @ORM\ManyToOne(targetEntity="Catalog", inversedBy="levels")
       * @ORM\JoinColumn(name="Catalogue_Code", referencedColumnName="Catalogue_Code")
       */
      private $catalog;
  
      /**
       * Set id
       *
       * @param string $id
       *
       * @return CatalogLevel
       */
      public function setId($id)
      {
          $this-&gt;id = $id;
  
          return $this;
      }
  
      /**
       * Get id
       *
       * @return string
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set catalogCode
       *
       * @param string $catalogCode
       *
       * @return CatalogLevel
       */
      public function setCatalogCode($catalogCode)
      {
          $this-&gt;catalogCode = $catalogCode;
  
          return $this;
      }
  
      /**
       * Get catalogCode
       *
       * @return string
       */
      public function getCatalogCode()
      {
          return $this-&gt;catalogCode;
      }
  }
  </code></pre>
  
  <p>I would like to remind you that this error occured on the editAction (it works very well on the addAction) when I display the pre-filled form.</p>
  
  <p>Thanks for your help !</p>