title: symfony2 Maximum function nesting level of '100' reached, aborting! with doctrine eventlistener
body: <p>I have eventlistener <code>preUpdate</code></p>
  
  <pre><code>public function preUpdate(PreUpdateEventArgs $args) {        
      $user = $args-&gt;getEntity();
      if($user instanceof \iTracker\UserBundle\Entity\User) {
          if($args-&gt;hasChangedField('userGroup')) {
  
              $old = $args-&gt;getOldValue('userGroup');
              $new = $args-&gt;getNewValue('userGroup');
  
              $em = $args-&gt;getEntityManager();
  
              $old-&gt;setAmount($old-&gt;getAmount() - 1);
              $em-&gt;persist($old);
  
              $new-&gt;setAmount($new-&gt;getAmount() + 1);
              $em-&gt;persist($new);
              $em-&gt;flush();
          }
      }
  }
  </code></pre>
  
  <p>And after submiting form i get <code>FatalErrorException: Error: Maximum function nesting level of '100' reached, aborting! in /var/www/issue/app/cache/dev/classes.php line 6123</code></p>
  
  <blockquote>
    <p>in /var/www/issue/app/cache/dev/classes.php line 6123 at
    ErrorHandler->handleFatal() in
    /var/www/issue/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php
    line 0 at NormalizerFormatter->normalize() in
    /var/www/issue/app/cache/dev/classes.php line 6198 at
    LineFormatter->normalize() in /var/www/issue/app/cache/dev/classes.php
    line 6112 at NormalizerFormatter->format() in
    /var/www/issue/app/cache/dev/classes.php line 6172 at
    LineFormatter->format() in /var/www/issue/app/cache/dev/classes.php
    line 6320 at AbstractProcessingHandler->handle() in
    /var/www/issue/app/cache/dev/classes.php line 6646 at
    Logger->addRecord() in /var/www/issue/app/cache/dev/classes.php line
    6710 at Logger->debug() in
    /var/www/issue/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
    line 72 at DbalLogger->log() in
    /var/www/issue/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php
    line 50 at DbalLogger->startQuery() in
    /var/www/issue/vendor/doctrine/dbal/lib/Doctrine/DBAL/Logging/LoggerChain.php
    line 50 at LoggerChain->startQuery() in
    /var/www/issue/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php
    line 774 at Connection->executeUpdate() in
    /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
    line 447 at BasicEntityPersister->_updateTable() in
    /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
    line 357 at BasicEntityPersister->update() in
    /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php
    line 984 at UnitOfWork->executeUpdates() in
    /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php
    line 317 at UnitOfWork->commit() in
    /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php
    line 355 at EntityManager->flush() in
    /var/www/issue/src/iTracker/UserBundle/Listener/UserGroupAmount.php
    line 41
    and this </p>
  </blockquote>
  
  <ul>
  <li>at UserGroupAmount->preUpdate() in
  /var/www/issue/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php
  line 61</li>
  <li>at ContainerAwareEventManager->dispatchEvent() in
  /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php
  line 980</li>
  <li>at UnitOfWork->executeUpdates() in
  /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php
  line 317</li>
  <li>at UnitOfWork->commit() in
  /var/www/issue/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php
  line 355</li>
  <li>at EntityManager->flush() in
  /var/www/issue/src/iTracker/UserBundle/Listener/UserGroupAmount.php
  line 41</li>
  </ul>
  
  <p>and this 5 errors are looped, which cause this exception </p>