the documentations says:
onAfterInsert() is called after a record is inserted into database, but before transaction commit. This method does not allow modifications of the current persistence context, however, database modifications can be done using QueryRunner.
After I insert a payment I want to calculate the sum of all the payments already recorded, including the one that I am inserting now. How can this be done with QueryRunner in a listener? Now it only gets the sum for previous payments (already committed) and I have to add the current one in script, but the logic for delete and update listener is not that simple.