Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

example of setFlushMode Auto vs Commit

Ranch Foreman
Posts: 1898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For everyone's reference, I modified Chapter 7's bulkQueryExample to demo the difference between setFlushMode commit and auto

From this example with FlushMode= COMMIT, the query only sees that Peter's manager from the DB, who is still Joan. The query does not see the update of department 1's manager in persistence context.
[Thumbnail for Peter_original_department.JPG]
Peter is in CA13 department
[Thumbnail for Update_Manager.JPG]
Update Engineering department's manager to Marcus
[Thumbnail for Peter_manager_not_updated.JPG]
Peter is now in Engineering department, but his manager is not updated
Himai Minh
Ranch Foreman
Posts: 1898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Execute the create tables and insert tables query in chapter 7 of this example.
Change this code and re run the servlet:

When the flush mode = AUTO, the department update in the persistence context is seen by the query. Now, the query sees Peter's new department and update his manager from Joan to Marcus.
[Thumbnail for Peter_original_dptment.JPG]
Peter is in CA13 department, with manager Joan
[Thumbnail for update_dpt_1_manager_to_Marcus.JPG]
Update department 1's manager to Marcus
[Thumbnail for Peter_updates.JPG]
Peter is now in Engineering department , and he gets a new manager
Creator of Enthuware JWS+ V6
Posts: 3345
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice example!

Have a Cow!
Nothing? Or something? Like this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic