title: Symfony2 updating data with a form
body: <p>I am trying to update the data in my database but unfortunately Symfony keeps creating new data for me. I have the following controller:</p>
  
  <pre><code>public function updateAction(Request $request,$id)
  {
      $em = $this-&gt;getDoctrine()-&gt;getManager();
      $product = $em-&gt;getRepository('AcmeStoreBundle:Product')-&gt;find($id);
  
      if (!$product) {
          throw $this-&gt;createNotFoundException(
              'No product found for id '.$id
          );
      }
  
      $form = $this-&gt;createForm(new ProductType(), $product);
  
      if($request-&gt;isMethod('POST')) {
          $form-&gt;bind($request);
          if($form-&gt;isValid()) {
              $em-&gt;persist($product);
              $em-&gt;flush();
              $this-&gt;get('session')-&gt;getFlashBag()-&gt;add('green', 'Product Updated!');
          } else {
              //$this-&gt;get('logger')-&gt;info('This will be written in logs');
              $this-&gt;get('session')-&gt;getFlashBag()-&gt;add('red', 'Update of Product Failed!');
          }
          return $this-&gt;redirect($this-&gt;generateUrl('acme_store_product_all'));
      }
  
      return $this-&gt;render('AcmeStoreBundle:Default:update.html.twig',array(
          'name' =&gt; $product-&gt;getName(),
          'updateForm' =&gt; $form-&gt;createView(),
      ));
  }
  </code></pre>
  
  <p>I just wondering what I am doing wrong. I new to Symfony</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>// Acme/StoreBundle/Form/Type/ProductType.php
  namespace Acme\StoreBundle\Form\Type;
  
  use Acme\StoreBundle\Entity\Category;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  
  class ProductType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('name');
          $builder-&gt;add('price');
          $builder-&gt;add('description');
          $builder-&gt;add('category', 'entity',array('class' =&gt; 'AcmeStoreBundle:Category',));
      }
  
      public function getName()
      {
          return 'name';
      }
  }
  </code></pre>