title: Catchable Fatal Error: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given
body: <p>I'm learning Symfony 2 and I got the following error when I submit a form: </p>
  
  <blockquote>
    <p>Catchable Fatal Error: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given, called in C:\xampp\htdocs\ppe2\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 555 and defined</p>
  </blockquote>
  
  <p>Here is my code : </p>
  
  <p>Controller : </p>
  
  <pre><code>    public function ajouterAction(Request $request){
  
           $sponsor = new Sponsor();
           $formulaire = $this-&gt;createForm(new SponsorType(), $sponsor)-&gt;add('Ajouter', 'submit');
  
           if ($formulaire-&gt;handleRequest($request)-&gt;isValid()) {
             $em = $this-&gt;getDoctrine()-&gt;getManager();
             $em-&gt;persist($sponsor);
             $em-&gt;flush();
  
             $request-&gt;getSession()-&gt;getFlashBag()-&gt;add('notice', 'Le sponsor a bien été modfié !');
  
             return $this-&gt;redirect($this-&gt;generateUrl('ffe_sponsor_voir', array('id' =&gt; $sponsor-&gt;getId())));
           }
  
           return $this-&gt;render('FFESponsorBundle:Sponsor:ajouter.html.twig', array(
             'formulaire' =&gt; $formulaire-&gt;createView(),
           ));
      }
  </code></pre>
  
  <p>My form type SponsorType : </p>
  
  <pre><code>public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('nom', 'text')
          -&gt;add('rue', 'text')
          -&gt;add('codePostal', 'text')
          -&gt;add('ville', 'text')
          -&gt;add('telephone', 'text')
          -&gt;add('mail', 'text')
          -&gt;add('nomRepresentant', 'text')
          -&gt;add('typeSponsor', 'entity', array(
                  'class'       =&gt; 'FFESponsorBundle:TypeSponsor',
                  'property'    =&gt; 'nom',
                  'multiple'    =&gt; true
          ))
      ;
  }
  </code></pre>
  
  <p>My typeSponsor and Sponsor entities are linked by a ManyToMany relation.</p>
  
  <p>Any idea what's wrong?</p>
  
  <p>UPDATE : </p>
  
  <p>This is my entity : </p>
  
  <pre><code>&lt;?php
  
  namespace FFE\SponsorBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Sponsor
   *
   * @ORM\Table()
   * @ORM\Entity(repositoryClass="FFE\SponsorBundle\Entity\SponsorRepository")
   */
  class Sponsor
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="nom", type="string", length=255)
       */
      private $nom;
  
      /**
       * @var string
       *
       * @ORM\Column(name="rue", type="string", length=255)
       */
      private $rue;
  
      /**
       * @var string
       *
       * @ORM\Column(name="codePostal", type="string", length=5)
       */
      private $codePostal;
  
      /**
       * @var string
       *
       * @ORM\Column(name="ville", type="string", length=45)
       */
      private $ville;
  
      /**
       * @var string
       *
       * @ORM\Column(name="telephone", type="string", length=10)
       */
      private $telephone;
  
      /**
       * @var string
       *
       * @ORM\Column(name="mail", type="string", length=255)
       */
      private $mail;
  
      /**
       * @var string
       *
       * @ORM\Column(name="nomRepresentant", type="string", length=45)
       */
      private $nomRepresentant;
  
      /**
        * @ORM\ManyToMany(targetEntity="FFE\SponsorBundle\Entity\TypeSponsor", cascade={"persist"})
        */
      private $typeSponsor;
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set nom
       *
       * @param string $nom
       * @return Sponsor
       */
      public function setNom($nom)
      {
          $this-&gt;nom = $nom;
  
          return $this;
      }
  
      /**
       * Get nom
       *
       * @return string 
       */
      public function getNom()
      {
          return $this-&gt;nom;
      }
  
      /**
       * Set rue
       *
       * @param string $rue
       * @return Sponsor
       */
      public function setRue($rue)
      {
          $this-&gt;rue = $rue;
  
          return $this;
      }
  
      /**
       * Get rue
       *
       * @return string 
       */
      public function getRue()
      {
          return $this-&gt;rue;
      }
  
      /**
       * Set codePostal
       *
       * @param string $codePostal
       * @return Sponsor
       */
      public function setCodePostal($codePostal)
      {
          $this-&gt;codePostal = $codePostal;
  
          return $this;
      }
  
      /**
       * Get codePostal
       *
       * @return string 
       */
      public function getCodePostal()
      {
          return $this-&gt;codePostal;
      }
  
      /**
       * Set ville
       *
       * @param string $ville
       * @return Sponsor
       */
      public function setVille($ville)
      {
          $this-&gt;ville = $ville;
  
          return $this;
      }
  
      /**
       * Get ville
       *
       * @return string 
       */
      public function getVille()
      {
          return $this-&gt;ville;
      }
  
      /**
       * Set telephone
       *
       * @param string $telephone
       * @return Sponsor
       */
      public function setTelephone($telephone)
      {
          $this-&gt;telephone = $telephone;
  
          return $this;
      }
  
      /**
       * Get telephone
       *
       * @return string 
       */
      public function getTelephone()
      {
          return $this-&gt;telephone;
      }
  
      /**
       * Set mail
       *
       * @param string $mail
       * @return Sponsor
       */
      public function setMail($mail)
      {
          $this-&gt;mail = $mail;
  
          return $this;
      }
  
      /**
       * Get mail
       *
       * @return string 
       */
      public function getMail()
      {
          return $this-&gt;mail;
      }
  
      /**
       * Set nomRepresentant
       *
       * @param string $nomRepresentant
       * @return Sponsor
       */
      public function setNomRepresentant($nomRepresentant)
      {
          $this-&gt;nomRepresentant = $nomRepresentant;
  
          return $this;
      }
  
      /**
       * Get nomRepresentant
       *
       * @return string 
       */
      public function getNomRepresentant()
      {
          return $this-&gt;nomRepresentant;
      }
  
      /**
       * Set typeSponsor
       *
       * @param \FFE\SponsorBundle\Entity\TypeSponsor $typeSponsor
       * @return Sponsor
       */
      public function setTypeSponsor(\FFE\SponsorBundle\Entity\TypeSponsor $typeSponsor = null)
      {
          $this-&gt;typeSponsor = $typeSponsor;
  
          return $this;
      }
  
      /**
       * Get typeSponsor
       *
       * @return \FFE\SponsorBundle\Entity\TypeSponsor 
       */
      public function getTypeSponsor()
      {
          return $this-&gt;typeSponsor;
      }
  }
  </code></pre>