为什么是“hibernate.connection.autocommit = true”不推荐在Hibernate? [英] Why is "hibernate.connection.autocommit = true" not recommended in Hibernate?

查看:264
本文介绍了为什么是“hibernate.connection.autocommit = true”不推荐在Hibernate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Hibernate API中,有一个属性 hibernate.connection.autocommit ,可以设置为true。

In Hibernate API, there is a property hibernate.connection.autocommit which can be set to true.

但在API中,他们提到不建议这样设置:

But in the API, they have mentioned that it is not recommended to set it like so:


为JDBC池连接启用自动提交功能(建议不要使用
)。

Enables autocommit for JDBC pooled connections (it is not recommended).

推荐的 ?
将此属性设置为true有什么不良影响?

Why is it not recommended ? What are the ill-effects of setting this property to true ?

推荐答案

默认情况下,autocommit值为false,因此,事务需要明确提交。这可能是为什么更改不会反映在数据库中的原因,否则可以在提交前尝试flush以强制更改。

By default the autocommit value is false, therefore the transaction needs to be commited explicitly. This might be the reason why the changes not getting reflected in database, else can try flush to force the changes before commit.

当您关闭会话时,在数据库中隐式提交[取决于实现]。

When you close the session, then it will get commited in database implicitly [depends on the implementation].

当你有级联事务&需要回滚原子性,你需要控制事务&在这种情况下,autocommit应为false。

When you have cascading transactions & needs to rollback for atomicity, you need to have control over transactions & in that case, autocommit should be false.

将autocommit设置为true或明确处理事务。

Either set autocommit as true or handle transactions explicitly.

a href =https://community.jboss.org/wiki/Non-transactionalDataAccessAndTheAuto-commitMode>这里是一个很好的解释。

Here is a good explanation on it.

与此相关的 Hibernate论坛

Stackoverflow问题

这篇关于为什么是“hibernate.connection.autocommit = true”不推荐在Hibernate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆