title: Symfony2 - EventListener changing data onFlush
body: <p>I am trying to generate a Pdf with  KnpSnappyBundle and save the position in doctrine when my Bill Entity is generated.</p>
  
  <p>I need the tamplating service for that, which i can't get inside an Entity.</p>
  
  <p>I read into EventListener and tried to get one to work.</p>
  
  <p>My config.yml</p>
  
  <pre><code>services:
      bill.listener:
          class: MyCompany\CompanyBundle\EventListener\BillListener
          tags:
              - { name: doctrine.event_listener, event: onFlush }
  </code></pre>
  
  <p>And my Listener</p>
  
  <pre><code>namespace MyCompany\CompanyBundle\EventListener;
  
  use Doctrine\ORM\Event\OnFlushEventArgs;
  
  class BillListener
  {
      public function onFlush(OnFlushEventArgs $args)
      {
          $em = $args-&gt;getEntityManager();
          $uow = $em-&gt;getUnitOfWork();
  
          foreach ($uow-&gt;getScheduledEntityInsertions() as $insertions) {
              foreach ($insertions as $entity) {
                  if ($entity instanceof Bill) {
                      $entity-&gt;setFilename("test.pdf");
  
                      $md = $em-&gt;getClassMetadata(get_class($entity));
                      $uow-&gt;recomputeSingleEntityChangeSet($md, $entity);
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>My Bill Entity has a setFilename function where I want to save the position of the generated Bill. But i can't get even that to work.</p>