Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setFlushMode (FlushModeType.AUTO) vs FlushModeType.COMMIT

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
For EntityManager or TypedQuery, what is the difference between FlushModeType.AUTO and COMMIT.
I have been reading the explanation from the book. But I still don't get it.
Thanks in advance.
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to do this code with both FlushTypeMode = AUTO and COMMIT, but the outputs on the screen of the messages are the same:


Message 13 is the same before the flush mode is set to either Auto or commit and after the flush mode is set.

13 : Does EJB 3.0 support inheritence? : Mon May 22 23:47:34 EDT 2006 : ACTIVE
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have no luck with this MessageBoardServlet to demo the difference between FlushModeType.COMMIT vs FlushModeType.AUTO.
But I found a luck with the bulkQueryExample in the same chapter.



//Sarah's manager is updated from Joan to Roberts' after the query is executed.
//The change happened in changeManagerForSarah is not committed.
direct employee of id 12 Roberts' : Sarah
direct employee of id 12 Roberts' : John
direct employee of id 12 Roberts' : Roberts
direct employee of id 12 Roberts' : Peter
direct employee of id 12 Roberts' : Marcus
direct employee of id 12 Roberts' : Roberts'

//Now, the changeManagerForSarah is committed. Her department is 3 with manager Dummy.
Employee 2 Sarah  has manager : 21


Refer to the screen shots of my DB.
sarahManagerIsJoan.JPG
[Thumbnail for sarahManagerIsJoan.JPG]
Department 2 has manager Joan, Sarah is in this department
updateScreen.JPG
[Thumbnail for updateScreen.JPG]
Update department 2
SarahInDept3withDummy.JPG
[Thumbnail for SarahInDept3withDummy.JPG]
Commit Sarah
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code remains the same as the above example except the FlushModeType is AUTO, not COMMIT.



  //Sarah's manager is changed from Joan to Dummy at first and the em automatically flushes the change to the DB
//Now, Sarah's manager is not changed from Joan to Roberts then to Dummy.
direct employee of id 12 Roberts' : John
direct employee of id 12 Roberts' : Roberts
direct employee of id 12 Roberts' : Peter
direct employee of id 12 Roberts' : Marcus
direct employee of id 12 Roberts' : Roberts'
Employee 2 Sarah  has manager : 21
originalEmployeeTable_autoFlushMode.JPG
[Thumbnail for originalEmployeeTable_autoFlushMode.JPG]
Department 2 is supervised by Joan originally
committedEmployeeTable_autoFlushMode.JPG
[Thumbnail for committedEmployeeTable_autoFlushMode.JPG]
Sarah is in deparment 3 supervised by Dummy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic