What is transaction.commit() in Hibernate?

前端 未结 2 1032
陌清茗
陌清茗 2020-12-09 12:31

What does transaction.commit() do?

Account account = new Account();
account.setId(100);
account = (Account) session.get(Account.class, accou         


        
2条回答
  •  有刺的猬
    2020-12-09 13:08

    Commit will make the database commit. The changes to persistent object will be written to database. Flushing is the process of synchronizing the underlying persistent store with persistant state held in memory. ie. it will update or insert into your tables in the running transaction, but it may not commit those changes (this depends on your flush mode).

    When you have a persisted object and you change a value on it, it becomes dirty and hibernate needs to flush these changes to your persistence layer. It may do this automatically for you or you may need to do this manually, that depends on your flush mode(auto or manual) :)

    So in short: transaction.commit() does flush the session, but it also ends the unit of work.

    There is a similar reference to your problem here

提交回复
热议问题