title: Symfony2 Form collection handle request error "Neither the property nor one of the methods exist and have public access"
body: <p>I have a problem when I want to handle form with collection</p>
  
  <p>I have two entities FeatureCategory and Feature</p>
  
  <p>User chooses one feature in every featureCategory (collection of featureCategories).</p>
  
  <p>Feature category entity:</p>
  
  <pre><code> class FeatureCategory
  {
      /**
       * @var \Doctrine\Common\Collections\Collection
       * @ORM\OneToMany(targetEntity="Site\BackendBundle\Entity\Feature", mappedBy="featureCategory", cascade={"persist"})
       */
      private $features;
  
      /**
       * Constructor
       */
      public function __construct()
      {
          $this-&gt;features = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
      /**
       * Add feature
       *
       * @param \Site\BackendBundle\Entity\Feature $feature
       * @return FeatureCategory
       */
      public function addFeature(\Site\BackendBundle\Entity\Feature $feature)
      {
  
          $feature-&gt;setFeatureCategory($this);
          $this-&gt;features[] = $feature;
  
          return $this;
      }
  
      /**
       * Remove feature
       *
       * @param \Site\BackendBundle\Entity\Feature $feature
       */
      public function removeFeature(\Site\BackendBundle\Entity\Feature $feature)
      {
          $this-&gt;features-&gt;removeElement($feature);
      }
  
      /**
       * Get features
       *
       * @return \Doctrine\Common\Collections\Collection
       */
      public function getFeatures()
      {
          return $this-&gt;features;
      }
  }
  </code></pre>
  
  <p>And feature entity:</p>
  
  <pre><code>class Feature
  {
      /**
       * @var \Site\BackendBundle\Entity\FeatureCategory
       *
       * @ORM\ManyToOne(targetEntity="Site\BackendBundle\Entity\FeatureCategory", inversedBy="features")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="feature_category_id", referencedColumnName="id")
       * })
       */
      private $featureCategory;
  
      /**
       * Set featureCategory
       *
       * @param \Site\BackendBundle\Entity\FeatureCategory $featureCategory
       * @return Feature
       */
      public function setFeatureCategory(\Site\BackendBundle\Entity\FeatureCategory $featureCategory = null)
      {
          $this-&gt;featureCategory = $featureCategory;
  
          return $this;
      }
  
      /**
       * Get featureCategory
       *
       * @return \Site\BackendBundle\Entity\FeatureCategory
       */
      public function getFeatureCategory()
      {
          return $this-&gt;featureCategory;
      }
  }
  </code></pre>
  
  <p>Feature categories form:</p>
  
  <pre><code>class FeatureCategoriesFormType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('featureCategories', 'collection', array(
                  'type' =&gt; 'site_frontend_feature_category',
                  'by_reference' =&gt; false
              ))
              -&gt;add('quantity', 'text', array(
                  'data' =&gt; 1
              ))
          ;
      }
  
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'validation_groups' =&gt; array('feature_categories')
          ));
      }
  
      public function getName()
      {
          return 'site_frontend_feature_categories';
      }
  }
  </code></pre>
  
  <p>And feature category form:</p>
  
  <pre><code>class FeatureCategoryFormType extends AbstractType
  {
  
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
  
          $builder-&gt;addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($builder)
          {
              $form = $event-&gt;getForm();
              $data = $event-&gt;getData();
  
              /* Check we're looking at the right data/form */
              if ($data instanceof FeatureCategory)
              {
                  $choices = $data-&gt;getFeatures();
                  $form
                      -&gt;add('features', 'entity', array(
                          'multiple'  =&gt; false,
                          'expanded'  =&gt; true,
                          'class' =&gt; 'SiteBackendBundle:Feature',
                          'property' =&gt; 'value',
                          'choices' =&gt; $choices,
                          'data' =&gt; null
                      ))
                      -&gt;add('name', 'hidden', array(
                          'read_only' =&gt; true,
                          'label' =&gt; $data-&gt;getName()
                      ))
                  ;
              }
          });
  
      }
  
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'Site\BackendBundle\Entity\FeatureCategory',
              'validation_groups' =&gt; array('feature_category')
          ));
      }
  
      public function getName()
      {
          return 'site_frontend_feature_category';
      }
  }
  </code></pre>
  
  <p>And finally my controller:</p>
  
  <pre><code>class OrderController extends Controller
  {
      public function addProductAction(Request $request, $slug)
      {
          $em = $this-&gt;get('doctrine.orm.default_entity_manager');
  
          $item = $em-&gt;getRepository('SiteBackendBundle:Product')
              -&gt;getItem($slug);
  
          if (!$item) {
              throw new NotFoundHttpException();
          }
  
          $featureCategories = $em-&gt;getRepository('SiteBackendBundle:FeatureCategory')
              -&gt;getListByProduct($item);
  
          $featureCategoriesForm = $this-&gt;createForm('site_frontend_feature_categories', array('featureCategories' =&gt; $featureCategories),
              array(
                  'method' =&gt; 'POST',
                  'action' =&gt; $this-&gt;generateUrl('user_order_add_product', array(
                      'slug' =&gt; $item-&gt;getSlug(),
                  ))
              )
          );
  
          if ($request-&gt;isXmlHttpRequest()) {
              if ($request-&gt;isMethod('POST')) {
                  $featureCategoriesForm-&gt;handleRequest($request);
  
                  if ($featureCategoriesForm-&gt;isValid()) {
                      //order add product logic
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>After <code>$featureCategoriesForm-&gt;handleRequest($request);</code> line, I got an error </p>
  
  <blockquote>
    <p>Neither the property "features" nor one of the methods
    "addFeatur()"/"removeFeatur()", "addFeature()"/"removeFeature()",
    "setFeatures()", "features()", "__set()" or "__call()" exist and have
    public access in class "Site\BackendBundle\Entity\FeatureCategory".</p>
  </blockquote>
  
  <p>Sorry for this long post
  Could anyone help?</p>