title: Symfony 2 UniqueEntity repositoryMethod fails on Update Entity
body: <p>I'm working on some simple script, but can't wrap my head around this problem.
  So here it is.</p>
  
  <pre><code>/**
   * Booking
   * @ORM\Table()
   * @ORM\Entity(repositoryClass="Tons\BookingBundle\Entity\BookingRepository")
   * @UniqueEntity(fields={"room", "since", "till"}, repositoryMethod="getInterferingRoomBookings")
   * @Assert\Callback(methods={"isSinceLessThanTill"}, groups={"search","default"})
   */
  class Booking
  </code></pre>
  
  <p>and repository Method</p>
  
  <pre><code>/**
       * Get room state for a certain time period
       *
       * @param array $criteria
       * @return array
       */
      public function getInterferingRoomBookings(array $criteria)
      {
          /** @var $room Room */
          $room = $criteria['room'];
          $builder = $this-&gt;getQueryForRoomsBooked($criteria);
          $builder-&gt;andWhere("ira.room = :room")-&gt;setParameter("room", $room);
          return $builder-&gt;getQuery()-&gt;getArrayResult();
      }
  </code></pre>
  
  <p>The problem is that this works on create methods like it should,
  but when updating existing entity - it violates this constrain.</p>
  
  <p>I tried to add Id constrain, but when creating entities, id is null, so repository Method don't even starts.
  Also i tried to remove Entity and then recreate it. like</p>
  
  <pre><code>$em-&gt;remove($entity);
  $em-&gt;flush();
  //-----------
  $em-&gt;persist($entity);
  $em-&gt;flush();
  </code></pre>
  
  <p>but this also does not work.</p>
  
  <p>Create Action</p>
  
  <pre><code> /**
       * Creates a new Booking entity.
       *
       * @Route("/create", name="booking_create")
       * @Method("POST")
       * @Template("TonsBookingBundle:Booking:new.html.twig")
       */
      public function createAction(Request $request)
      {
          $entity = new Booking();
          $form = $this-&gt;createForm(new BookingType(), $entity);
          $form-&gt;bind($request);
          if ($form-&gt;isValid())
          {
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $room = $entity-&gt;getRoom();
              if($room-&gt;getLocked() &amp;&amp; $room-&gt;getLockedBy()-&gt;getId() === $this-&gt;getUser()-&gt;getId())
              {
                  $entity-&gt;setCreatedAt(new \DateTime());
                  $entity-&gt;setUpdatedAt(new \DateTime());
                  $entity-&gt;setManager($this-&gt;getUser());
  
                  $em-&gt;persist($entity);
                  $room-&gt;setLocked(false);
                  $room-&gt;setLockedBy(null);
                  $room-&gt;setLockedAt(null);
                  $em-&gt;persist($room);
                  $em-&gt;flush();
                  return $this-&gt;redirect($this-&gt;generateUrl('booking_show', array('id' =&gt; $entity-&gt;getId())));
              }
              else
              {
                  $form-&gt;addError(new FormError("Номер в текущий момент не заблокирован или заблокирован другим менеджером"));
                  return array(
                      'entity' =&gt; $entity,
                      'form' =&gt; $form-&gt;createView(),
                  );
              }
          }
  
          return array(
              'entity' =&gt; $entity,
              'form' =&gt; $form-&gt;createView(),
          );
      }
  </code></pre>
  
  <p>Update Action</p>
  
  <pre><code> /**
       * Edits an existing Booking entity.
       *
       * @Route("/edit/{id}/save", name="booking_update")
       * @Method("PUT")
       * @Template("TonsBookingBundle:Booking:edit.html.twig")
       */
      public function updateAction(Request $request, $id)
      {
          /** @var $em EntityManager */
          $em = $this-&gt;getDoctrine()-&gt;getManager();
  
          $entity = $em-&gt;getRepository('TonsBookingBundle:Booking')-&gt;find($id);
  
          if (!$entity) {
              throw $this-&gt;createNotFoundException('Unable to find Booking entity.');
          }
  
          $editForm = $this-&gt;createForm(new BookingType(), $entity);
          $editForm-&gt;bind($request);
  
          if ($editForm-&gt;isValid()) {
              $em-&gt;persist($entity);
              $em-&gt;flush();
  
              return $this-&gt;redirect($this-&gt;generateUrl('booking_edit', array('id' =&gt; $id)));
          }
  
          return array(
              'entity' =&gt; $entity,
              'form' =&gt; $editForm-&gt;createView(),
          );
      }
  </code></pre>