Hi,
What a coincidence! I've just finished an article about JPA and the way it flushes entity changes to database.
Zasady zapisu zmian do bazy danych w JPA -
http://www.jaceklaskowski.pl/wiki/Zasady_zapisu_zmian_do_bazy_danych_w_JPA
It's in Polish, but you may find the junit test pretty easy to run without having to understand the entire article.
In summary, the default setting of JPA is to flush entity changes at the time JPA provider decides it's time to do so (FlushModeType.AUTO). It means that when an entity is managed (controlled by an entity manager) entity changes won't be in the database at the time the change's made. It's up to JPA provider to decide when it should be written to database.
When you set FlushModeType.COMMIT *every* JPA provider has to save entity changes to database at transaction commit. You may be wondering why I highlighted the word *every*, right? It's because OpenJPA and TopLink update database at commit no matter of FlushModeType setting whereas Hibernate saves changes before a query's executed.
See sections 3.2 and 3.6.2 of JPA specification.
Jacek
[Message sent by forum member 'jlaskowski' (jlaskowski)]
http://forums.java.net/jive/thread.jspa?messageID=250442