• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

example of setFlushMode Auto vs Commit

 
Ranch Hand
Posts: 1749
12
  • 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.
Peter_original_department.JPG
[Thumbnail for Peter_original_department.JPG]
Peter is in CA13 department
Update_Manager.JPG
[Thumbnail for Update_Manager.JPG]
Update Engineering department's manager to Marcus
Peter_manager_not_updated.JPG
[Thumbnail for Peter_manager_not_updated.JPG]
Peter is now in Engineering department, but his manager is not updated
 
Himai Minh
Ranch Hand
Posts: 1749
12
  • 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.
Peter_original_dptment.JPG
[Thumbnail for Peter_original_dptment.JPG]
Peter is in CA13 department, with manager Joan
update_dpt_1_manager_to_Marcus.JPG
[Thumbnail for update_dpt_1_manager_to_Marcus.JPG]
Update department 1's manager to Marcus
Peter_updates.JPG
[Thumbnail for Peter_updates.JPG]
Peter is now in Engineering department , and he gets a new manager
 
Creator of Enthuware JWS+ V6
Posts: 3293
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice example!

Have a Cow!
 
Don't MAKE me come back there with this tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!