紙上得來終覺淺简僧,絕知此事要躬行
這次的主角是 @Transactional(propagation= Propagation.MANDATORY );調(diào)用者方法必須存在事務搪柑,不然報出IllegalTransactionStateException 異常
繼續(xù)驗證
1、InsertUser 使用mandatory 索烹,InsertCuser不加注解
InsertUser 報異常
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
2工碾、InsertUser 不加注解 ,InsertCuser使用mandatory
InsertUser 非事務方式執(zhí)行
InsertCuser報異常
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
3术荤、InsertUser 使用 mandatory倚喂,InsertCuser 使用requires_new
InsertUser 報異常
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
4、InsertUser 使用 requires_new,InsertCuser 使用mandatory
InsertUser 將事務傳播給InsertCuser 端圈,兩者使用同一事務
5焦读、InsertUser 使用 mandatory,InsertCuser 使用not_supported
InsertUser 報異常
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
6舱权、InsertUser 使用not_supported 矗晃,InsertCuser 使用mandatory
InsertUser 以非事務方式執(zhí)行,InsertCuser 報錯
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
7宴倍、InsertUser 使用 mandatory张症,InsertCuser 使用never
InsertUser 報異常
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
8、InsertUser 使用 never鸵贬,InsertCuser 使用 mandatory
InsertUser 非事務狀態(tài)執(zhí)行俗他,InsertCuser報異常
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
9 、InsertUser 使用 mandatory阔逼,InsertCuser 使用 nested
InsertUser 報異常
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
10兆衅、InsertUser 使用 nested ,InsertCuser 使用 mandatory
InsertUser 將事務傳播給InsertCuser 嗜浮,兩者使用同一事務
大總結(jié)
實驗 | InsertUser 調(diào)用者
|
InsertCuser 被調(diào)用者
|
結(jié)果 |
---|---|---|---|
1 | mandatory | 不加 | InsertUser 報異常IllegalTransactionStateException |
2 | 不加 | mandatory | InsertUser 非事務方式執(zhí)行羡亩,InsertCuser報異常 IllegalTransactionStateException |
3 | mandatory | requires_new | InsertUser 報異常IllegalTransactionStateException |
4 | requires_new | mandatory | InsertUser 將事務傳播給InsertCuser ,兩者使用同一事務 |
5 | mandatory | not_supported | InsertUser 報異常IllegalTransactionStateException |
6 | not_supported | mandatory | InsertUser 以非事務方式執(zhí)行危融,InsertCuser 報錯IllegalTransactionStateException |
7 | mandatory | never | InsertUser 報異常IllegalTransactionStateException |
8 | never | mandatory | InsertUser 以非事務方式執(zhí)行畏铆,InsertCuser 報錯IllegalTransactionStateException |
9 | mandatory | nested | InsertUser 報異常IllegalTransactionStateException |
10 | nested | mandatory | InsertUser 將事務傳播給InsertCuser ,兩者使用同一事務 |
繼續(xù)第四篇
http://www.reibang.com/p/08e5c7d30d51