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

session.flush() vs. transaction.commit()

 
Joseph Sweet
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

In Hibernate, what is actually the difference between session.flush() and transaction.commit()?

The online API does not really explain why we need them both. It seems to me like they do pretty much the same.

Look at this code, taken from The Hibernate Tutorial:

 
Saket Barve
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my current project at work, we don't work with Transactions directly; it is the application server which pretty much handles that for us. So calling is all we have to deal with.

In any case, they are intended to perform the same thing, namely synchronize. The description can be found in the section Flushing the Session of Hibernate Documentation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic