According to documentation you should not invoke flush
after every change to an entity or every single invocation of persist/remove/... This is an anti-pattern and unnecessarily reduces the performance of your application. Instead, form units of work that operate on your objects and call flush
when you are done. While serving a single HTTP request there should be usually no need for invoking flush
more than 0-2 times.