5.
Cache Management

public void flush();

The flush method writes any changes that have been made
in the current transaction to the datastore. If the EntityManager
does not already have a connection to the datastore, it obtains one
for the flush and retains it for the duration of the transaction. Any exceptions
during flush cause the transaction to be marked for rollback. See
Chapter 9,
Transaction
.

Flushing requires an active transaction. If there isn't a transaction in
progress, the flush method throws a
TransactionRequiredException.

The EntityManager's FlushMode property
controls whether to flush transactional changes before executing queries. This
allows the query results to take into account changes you have made during the
current transaction. Available
javax.persistence.FlushModeType constants are:

COMMIT: Only flush when committing, or when told to do so
through the flush method. Query results may not take
into account changes made in the current transaction.

AUTO: The implementation is permitted to flush before
queries to ensure that the results reflect the most recent object state.