title: Inserting element in doctrine listener
body: <p>I have setup a doctrine listener which is fired on different database actions and creates a log entity and insert it into the database.</p>
  <pre><code>class FOO { 
   // [...]
   public function onFlush(OnFlushEventArgs $args)
   {
       foreach ($args-&gt;getEntityManager()-&gt;getUnitOfWork()-&gt;getScheduledEntityUpdates() as $entity) {
                  $this-&gt;createLog('edit', $entity);
       }
   }
  
  
   private function createLog($action, $entity)
   {
          if ($entity instanceof Log) {
              return;
          }
          $log = new Log;
          $log-&gt;setAction($action);
          $log-&gt;setTime(new \DateTime);
          $log-&gt;setForeignId($entity-&gt;getId());
          $log-&gt;setUser($this-&gt;getUser());
          $t            = explode('\\', get_class($entity));
          $entity_class = strtolower(end($t));
          $log-&gt;setEntity($entity_class);
          $this-&gt;getEntityManager()-&gt;persist($log);
    }
  // [...]
  }
  </code></pre>
  <p>When I update an object, I get the following error:</p>
  <blockquote>
  <p>SQLSTATE[HY093]: Invalid parameter number: no parameters were bound</p>
  </blockquote>
  <p>In the profiler I see this query:</p>
  <blockquote>
  <p>INSERT INTO vvg_logs (action, entity, foreign_id, user_id, time) VALUES (?, ?, ?, ?, ?)</p>
  <p>Parameters: { }</p>
  </blockquote>
  <p>How could I resolve this problem?</p>
  <p><strong>UPDATE</strong>
  Here is my new topic connecting to this question: <a href="https://stackoverflow.com/questions/9606450/symfony2-inserting-element-inside-doctrine-postpersist-listener">LINK</a></p>