1、required
explain:表示当前方法必须在一个具有事务的上下文中运行,如有客户端有事务在进行,那么被调用端将在该事务中运行,否则的话重新开启一个事务(如果被调用端发生异常,那么调用端和被调用端事务都将回滚)。
method a invoke method b(required):
a exception,ab rollback;
b exception, a not catch, ab rollback;
b exception, a catch, b rollback, a submit, throw Transaction rolled back because it has been marked as rollback-only;
2、supports
explain:表示当前方法不必需要具有一个事务上下文,但是如果有一个事务的话,它也可以在这个事务中运行。
method a invoke method b (supports):
a not transaction, ab not rollback;
a transaction, a exception, ab rollback;
a transaction, b exception, a not catch, ab rollback;
a transaction, b exception, a catch, throw Transactionrolled back because it has been marked as rollback-only。
3、mandatory
explain:表示当前方法必须在一个事务中运行,如果没有事务,将抛出异常。
method a invoke method b (mandatory):
a not transaction,b run throw No existingtransaction found for transaction marked with propagation 'mandatory';
a transaction , a exception, ab rollback;
a transaction , b exception , a not catch, ab rollback;
a transaction , b exception , a catch, ab Transaction rolled back because ithas been marked as rollback-only。
4、nested:
explain:表示如果当前方法正有一个事务在运行中,则该方法应该运行在一个嵌套事务中,被嵌套的事务可以独立于被封装的事务中进行提交或者回滚。如果封装事务存在,并且外层事务抛出异常回滚,那么内层事务必须回滚,反之,内层事务并不影响外层事务。如果封装事务不存在,则同REQUIRED的一样。
method a invoke method b (nested):
a not transaction, b transaction, b exception, b rollback, a not rollback;
a transaction, a exception, ab rollback;
a transaction, b exception, a not catch, ab rollback;
a transaction, b exception, a catch, b rollback, a not rollback。
5、never
explain:表示当方法务不应该在一个事务中运行,如果存在一个事务,则抛出异常。
method a invoke method b (never):
a transaction, throw Existingtransaction found for transaction marked with propagation 'never'。
6、requireds_new
explain:表示当前方法必须运行在它自己的事务中。一个新的事务将启动,而且如果有一个现有的事务在运行的话,则这个方法将在运行期被挂起,直到新的事务提交或者回滚才恢复执行。
method a invoke method b (requires_new):
a transaction, a exception, a rollback, b not rollback;
a transaction, b exception, a not catch, ab rollback;
a transaction, b exception, a catch, a not rollback, b rollback。
7、not supported
explain:表示该方法不应该在一个事务中运行。如果有一个事务正在运行,他将在运行期被挂起,直到这个事务提交或者回滚才恢复执行。
method a invoke method b (not_supported):
a transaction, b exception, a not cath, a rollback, b throw exception before operate not rollback;
a transaction, b exception, a catch, a not rollback, b throw exception before operate not rollback。
Spring传播行为默认:required
Spring隔离级别默认(Mysql):可重复读
Spring隔离级别默认(Oracle):读已提交