Spring 中事务属性详解
-
Isolation 指定事务的隔离级别
- 读已提交 READ_COMMITTED
- 读未提交 READ_UNCOMMITTED
- 可重复读 REPEATABLE_READ
- 串行化 SERIALIZABLE
- 默认值 DEFAULT: (MySQL: 可重复读、Oracle: 读已提交)
-
timeout 设置单位为秒的超时。 默认值是 -1 表示使用数据库的设置。
-
readOnly
设置是否是只读事务。- 当你能确保整个事务过程中只对数据库执行Select操作的时候,如果将此属性设置为true,则会自动进行优化,提高性能。
-
Propagation
事务的传播属性(特有的精细化的控制),解决的是事务嵌套的问题-
SUPPORTS(1), //支持 Support a current transaction, execute non-transactionally if none exists. 支持当前事务,如果当前没事务,则在非事务的环境下执行。 MANDATORY(2), //强制要求 Support a current transaction, throw an exception if none exists. 支持当前事务,如果当前没事务则抛出异常。 NOT_SUPPORTED(4), //不支持 Execute non-transactionally, suspend the current transaction if one exists. 在非事务的环境下执行,如果当前存在事务&
-