title: Doctrine Symfony2 persist association entity with existing one
body: <p>I have two entities Product and Category with association of type ManyToOne, Supposed i want to create a new Product and i already know its category (means i know ID category)</p>
  
  <p>CLASS PRODUCT</p>
  
  <pre><code>/**
   * @ORM\Entity
   * @ORM\Table(name="product")
   */
  class Product
  {
      /**
       * @ORM\Column(type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @ORM\Column(type="string", length=100)
       */
      private $name;
  
      /**
       * @ORM\ManyToOne(targetEntity="Category")
       * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
       */
      private $category;
  }
  </code></pre>
  
  <p>CLASS CATEGORY</p>
  
  <pre><code>/**
   * @ORM\Entity
   * @ORM\Table(name="category")
   */
  class Category
  {
      /**
       * @ORM\Column(type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  }
  </code></pre>
  
  <p>SCRNARIO: creat new product and supposed i know the ID category so we dont need to use the find method of Category Entity to get it (making things faster)</p>
  
  <pre><code>$em = $this-&gt;get('doctrine')-&gt;getManager();
  $category = new Category();
  $category-&gt;setId(12);
  $product = new Product();
  $product-&gt;setName('product 1');
  $product-&gt;setCategory($category);
  $em-&gt;persist($product);
  $em-&gt;flush();
  </code></pre>
  
  <p>the code above is not working it generate an exception:</p>
  
  <blockquote>
    <p>A new entity was found through the relationship
    'AOBundle\Entity\Product#category' that was not configured to cascade
    persist operations for entity:
    AOBundle\Entity\Category@0000000049a05dc500000000723a1be6. To solve
    this issue: Either explicitly call EntityManager#persist() on this
    unknown entity or configure cascade persist this association in the
    mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot
    find out which entity causes the problem implement
    'AOBundle\Entity\Category#__toString()' to get a clue.</p>
  </blockquote>
  
  <p>but when i use the find method to get the category instance it worked, but i don't like this solution i want to make the application faster is there any solution.
  Thanks</p>