title: [Symfony2]Catchable Fatal Error: Object of class [...] could not be converted to string
body: <p>I'm currently working on a project for my on the job trainning.
  But I'm in front of an error which and can't resolve.</p>
  
  <p>So, I use a relation ManyToOne to join 2 things, products in category.</p>
  
  <p>But when I want to add a product I have this error :</p>
  
  <blockquote>
    <p>ContextErrorException: Catchable Fatal Error: Object of class Sam\VitrineBundle\Entity\Categorie could not be converted to string in D:\DOCUMENTS\Dropbox\COURS\S4\STAGE\Symfony\src\Sam\VitrineBundle\Entity\Produit.php line 124</p>
  </blockquote>
  
  <p><strong>My controller</strong>, code where I have the error.</p>
  
  <pre><code>...
  $catRepo = $this-&gt;getDoctrine()-&gt;getManager()-&gt;getRepository('SamVitrineBundle:Categorie');
  $cat = $catRepo-&gt;findOneById($form["categorie"]-&gt;getData());
  $product -&gt; setCategorie($cat);
  ...
  </code></pre>
  
  <p><strong>My entity</strong>, Product</p>
  
  <pre><code>...
      /**
       * @ORM\ManyToOne(targetEntity="Categorie", inversedBy="produits", cascade={"remove"})
       * @ORM\JoinColumn(name="categorie_id", referencedColumnName="id")
       */
      protected $categorie;
  
      /**
       * Set categorie
       *
       * @param Sam\VitrineBundle\Entity\Categorie $categorie
       */
      public function setCategorie(\Sam\VitrineBundle\Entity\Categorie $categorie)
      {
        $this-&gt;$categorie = $categorie;
      }
  
      /**
       * Get categorie
       *
       * @return Sam\VitrineBundle\Entity\Categorie 
       */
      public function getCategorie()
      {
        return $this-&gt;categorie;
      }
  ...
  </code></pre>
  
  <p>I'm sorry, some variable are in French.
  categorie -> category
  produit -> product</p>
  
  <p>If someone can help me.
  Ask me if you want more informations, but I give you the main informations which I think the error comes from.</p>
  
  <pre><code>[1] Symfony\Component\Debug\Exception\DummyException: 
      at n/a
          in D:\DOCUMENTS\Dropbox\COURS\S4\STAGE\Symfony\vendor\symfony\symfony\src\Symfony\Component\Debug\ErrorHandler.php line 174
  
      at Symfony\Component\Debug\ErrorHandler-&gt;handle('4096', 'Object of class Sam\VitrineBundle\Entity\Categorie could not be converted to string', 'D:\DOCUMENTS\Dropbox\COURS\S4\STAGE\Symfony\src\Sam\VitrineBundle\Entity\Produit.php', '124', array('categorie' =&gt; object(Categorie)))
          in D:\DOCUMENTS\Dropbox\COURS\S4\STAGE\Symfony\src\Sam\VitrineBundle\Entity\Produit.php line 124
  
      at Sam\VitrineBundle\Entity\Produit-&gt;setCategorie(object(Categorie))
          in D:\DOCUMENTS\Dropbox\COURS\S4\STAGE\Symfony\src\Sam\VitrineBundle\Controller\VitrineController.php line 113
  
      at Sam\VitrineBundle\Controller\VitrineController-&gt;addProductAction()
          in  line 
  
      at call_user_func_array(array(object(VitrineController), 'addProductAction'), array())
          in D:\DOCUMENTS\Dropbox\COURS\S4\STAGE\Symfony\app\bootstrap.php.cache line 2925
  
      at Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(object(Request), '1')
          in D:\DOCUMENTS\Dropbox\COURS\S4\STAGE\Symfony\app\bootstrap.php.cache line 2897
  
      at Symfony\Component\HttpKernel\HttpKernel-&gt;handle(object(Request), '1', true)
          in D:\DOCUMENTS\Dropbox\COURS\S4\STAGE\Symfony\app\bootstrap.php.cache line 3036
  
      at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel-&gt;handle(object(Request), '1', true)
          in D:\DOCUMENTS\Dropbox\COURS\S4\STAGE\Symfony\app\bootstrap.php.cache line 2304
  
      at Symfony\Component\HttpKernel\Kernel-&gt;handle(object(Request))
          in D:\DOCUMENTS\Dropbox\COURS\S4\STAGE\Symfony\web\app_dev.php line 28
  </code></pre>