A call to EntityManager.flush();
will force the data to be persisted in the database immediately as EntityManager.persist()
will not (depending on how the EntityManager is configured: FlushModeType (AUTO or COMMIT) by default is set to AUTO and a flush will be done automatically. But if it’s set to COMMIT the persistence of the data to the underlying database will be delayed until the transaction is committed.