So when you call EntityManager.persist()
, it only makes the entity get managed by the EntityManager
and adds it (entity instance) to the Persistence Context
. An Explicit flush()
will make the entity now residing in the Persistence Context
to be moved to the database (using a SQL).
Without flush(), this (moving of entity from Persistence Context
to the database) will happen when the Transaction to which this Persistence Context
is associated is committed.