What's the use of session.flush() in Hibernate

后端 未结 9 1180
甜味超标
甜味超标 2020-11-28 01:38

When we are updating a record, we can use session.flush() with Hibernate. What\'s the need for flush()?

9条回答
  •  甜味超标
    2020-11-28 02:09

    I only know that when we call session.flush() our statements are execute in database but not committed.

    Suppose we don't call flush() method on session object and if we call commit method it will internally do the work of executing statements on the database and then committing.

    commit=flush+commit (in case of functionality)

    Thus, I conclude that when we call method flush() on Session object, then it doesn't get commit but hits the database and executes the query and gets rollback too.

    In order to commit we use commit() on Transaction object.

提交回复
热议问题