title: Symfony2: Retrieve entity and modify it ==> SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-170' for key 'PRIMARY'
body: <p>I have an entity and I would like to change some values.</p>
  
  <p>So </p>
  
  <ol>
  <li>I retrieve my entity</li>
  <li>I change values</li>
  <li>I persist my entity and I flush</li>
  </ol>
  
  <p>... But I have this error:</p>
  
  <pre><code>SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-170' for key 'PRIMARY' 
  </code></pre>
  
  <p>Here the code</p>
  
  <pre><code>/**
   *
   * @ORM\Table(name="entity")
   * @ORM\Entity(repositoryClass="App\Bundle\Entity\EntityRepository")
   * @ORM\OrderBy({"date" = "ASC"})
   */
  class Entity
  {
        /**
        * @var integer $id
        *
        * @ORM\Column(name="id", type="integer")
        * @ORM\Id
        * @ORM\GeneratedValue(strategy="AUTO")
        */
       private $id; 
       // ...
  }
  </code></pre>
  
  <p>I retrieve my entity like this:</p>
  
  <pre><code>function get(){
         $query = $repository-&gt;createQueryBuilder('E')
          -&gt;select ('E')          
              -&gt;where('(E.type=:type) AND (E.m = :id)')
              -&gt;setParameter('type',  $pType)
              -&gt;setParameter('id',  $pMediaId)
          -&gt;getQuery();
          return $query-&gt;getResult();
   }
  </code></pre>
  
  <p>And persit</p>
  
  <pre><code>$entity = $this-&gt;em-&gt;get(); // I have the correct value
  entity-&gt;setTitle('My new title');
  $this-&gt;em-&gt;persist($entity);
  
  $this-&gt;em-&gt;flush();
  </code></pre>
  
  <p>Please help me</p>
  
  <p>See ya</p>
  
  <p>Sam</p>