title: Persisting new associated entity in preFlush handler (endless recursion)
body: <p>I've created a entity listener for a given entity <code>Foo</code>, which listens to the <code>preFlush</code> event. I want to create a new <code>Bar</code> entity whenever the <code>Foo</code> entity is updated or created.
  My problem is the preFlush event is triggered again by the <code>computeChangeSets()</code> resulting in an endless loop. Anyone have a solution or an alternative method to approach this use case?</p>
  
  <pre><code>class SomeListener
  {
      /**
       * @ORM\preFlush
       */
      public function onPreFlush(Foo $foo, PreFlushEventArgs $eventArgs)
      {
          $em = $eventArgs-&gt;getEntityManager();
          $uow = $em-&gt;getUnitOfWork();
  
          $bar = new Bar();
          $bar-&gt;setX('test');
          $foo-&gt;addBar($bar);
  
          $em-&gt;persist($bar);
  
          $meta = $em-&gt;getClassMetadata(get_class($foo));
          $uow-&gt;recomputeSingleEntityChangeSet($meta, $foo);
          $uow-&gt;computeChangeSets(); //This line invokes preFlush listener again
      }
  }
  </code></pre>