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):讀已提交