您好,登錄后才能下訂單哦!
一. 事務注解限制條件
1. 不允許在private方法上面
2. 不能在非事務方法里面調用事務方法
二. 實現機制-異常捕獲
Describes transaction attributes on a method or class. This annotation type is generally directly comparable to Spring's org.springframework.transaction.interceptor.RuleBasedTransactionAttribute class, and in fact AnnotationTransactionAttributeSource will directly convert the data to the latter class, so that Spring's transaction support code does not have to know about annotations. If no rules are relevant to the exception, it will be treated like org.springframework.transaction.interceptor.DefaultTransactionAttribute (rolling back on RuntimeException and Error but not on checked exceptions). For specific information about the semantics of this annotation's attributes, consult the org.springframework.transaction.TransactionDefinition and org.springframework.transaction.interceptor.TransactionAttribute javadocs.
所以如果操作數據庫的時候把異常捕獲了,那么將不能回滾。
三. 手動回滾
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
所以為了解決這種矛盾,可以捕獲異常后,在catch里面手動調用回滾。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。