Some confusing explanation:
flush(); Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.it will update or insert into
When the transaction commits the entity manager does that flush-ing for you. In some case, like handling optimistic locking in a container-managed transaction, you may need to manually invoke the flush method to catch and handle specific locking exception.