Doctrine, using count in postPersist will ignore inserted entity

  doctrine, doctrine-orm, event-listener, symfony

After I insert a line in a table, I use postPersist event to count all entities that match my criteria. The problem is that the last inserted line is sometimes ignored. I tried to use postFlush event but there’s no way to know what are the flushed entities. Can anyone help me with a solution?

Source: Symfony Questions