The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

CatchSandeepVaid (23) [Avatar] Offline
[P-331 of EJB3 In Action Book] states:
"By default, the database flush mode is set to AUTO. This means that the Entity-Manager performs a flush operation automatically as needed.
In general, this occurs at the end of a transaction for transaction-scoped EntityManagers and when the persistence context is closed for
application-managed or extendedscope EntityManagers. In addition, if entities with pending changes are used in a query, the persistence
provider will flush changes to the database before executing the query.If the flush mode is set to COMMIT, the persistence provider will
only synchronize with the database when the transaction commits.However, you should be careful with this, as it will be your responsibility
to synchronize entity state with the database before executing a query. If you don’t do this and an EntityManager query returns stale
entities from the database, the application can wind up in an inconsistent state."

[P-353 EJB3 In Action Book] states:
"If the Query is set to FlushModeType.COMMIT, the effect of updates made to entities in the persistence context is not defined
by the specification, and the actual behavior is implementation specific".

So setting the flush mode as COMMIT on EntityManager and Query have different results..Right ??
dpanda (136) [Avatar] Offline
Re: EntityManager.setFlushMode(COMMIT) Vs. Query.setFlushMode(COMMIT)
It may depend upon the implementation!