首页 > 解决方案 > 为什么休眠在插入和更新之前显示提交日志?

问题描述

休眠日志显示:

[debug] o.h.e.t.i.TransactionImpl - begin
do stuff...
[debug] o.h.e.t.i.TransactionImpl - committing
do more stuff... inserts, updates etc...
[debug] o.h.e.j.i.JdbcCoordinatorImpl - HHH000420: Closing un-released batch

当它“应该”这样做时

[debug] o.h.e.t.i.TransactionImpl - begin
do stuff...
do more stuff... inserts, updates etc...
[debug] o.h.e.t.i.TransactionImpl - committing

我将整个事情包装在一个事务中,所以我不认为这是我的代码的问题。我错过了什么吗?

标签: javahibernate

解决方案


Hibernate 有 3 种状态:Transient、Persistent 和 Detached。我认为它会显示commit从瞬态状态变为持久状态的时间。但是,这并不意味着事务真正提交。只是意味着对象已被 Hibernate 控制并准备好提交到数据库一段时间(取决于 Hibernate 内部机制)。如果我错了,请纠正我。


推荐阅读