title: The form's view data is expected to be an instance of MyEntity but is an instance of ArrayCollection
body: <p>I can create a form which works fine but getting errors when trying to flush data to the database:</p>
  
  <p>The controller action looks like this:</p>
  
  <pre><code>$purchase = new Purchase();
          $form = $this-&gt;createFormBuilder($purchase)
              -&gt;add('addresses', AddressType::class)
              -&gt;add('quantity', IntegerType::class)
              -&gt;add('toBeDeliveredAt', DateType::class)
              -&gt;add('comment', TextareaType::class)
              -&gt;add('save', SubmitType::class, array('label' =&gt; 'Submit'))
              -&gt;getForm();
  
          $form-&gt;handleRequest($request);
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $em-&gt;persist($purchase);
              $em-&gt;flush();
          }
  </code></pre>
  
  <p>Class AddressType looks like this:</p>
  
  <pre><code>public function buildForm(FormBuilderInterface $builder, array $options)
  
  {
      $builder
          -&gt;add('title', TextType::class)
          -&gt;add('firstname', TextType::class)
          -&gt;add('lastname', TextType::class)
          -&gt;add('street', TextType::class)
          -&gt;add('city', TextType::class)
          -&gt;add('zipcode', TextType::class)
          -&gt;add('country', TextType::class)
          -&gt;add('phone', TextType::class)
          -&gt;add('email', EmailType::class);
  }
  
  public function configureOptions(OptionsResolver $resolver)
  {
      $resolver-&gt;setDefaults(array(
          'data_class' =&gt; 'XxxBundle\Entity\Address'
      ));
  }
  </code></pre>
  
  <p>But that gives me the following error:</p>
  
  <blockquote>
    <p>The form's view data is expected to be an instance of class
    XxxBundle\Entity\Address, but is an instance of class
    Doctrine\Common\Collections\ArrayCollection. You can avoid this error
    by setting the "data_class" option to null or by adding a view
    transformer that transforms an instance of class
    Doctrine\Common\Collections\ArrayCollection to an instance of
    XxxBundle\Entity\Address.</p>
  </blockquote>
  
  <p>If I set the <code>data_class</code> option to null I get</p>
  
  <blockquote>
    <p>Warning: spl_object_hash() expects parameter 1 to be object, string given</p>
  </blockquote>
  
  <p>How can I add a view transformer that transforms an instance of class ArrayCollection to an instance of Address?</p>