Skip to content

Commit 2de488e

Browse files
committed
Stronger explanation of default rollback rules
Issue: SPR-14994 (cherry picked from commit 0296c7c)
1 parent c732f38 commit 2de488e

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Diff for: spring-tx/src/main/java/org/springframework/transaction/annotation/Transactional.java

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,8 @@
3636
* does not have to know about annotations. If no rules are relevant to the exception,
3737
* it will be treated like
3838
* {@link org.springframework.transaction.interceptor.DefaultTransactionAttribute}
39-
* (rolling back on runtime exceptions).
39+
* (rolling back on {@link RuntimeException} and {@link Error} but not on checked
40+
* exceptions).
4041
*
4142
* <p>For specific information about the semantics of this annotation's attributes,
4243
* consult the {@link org.springframework.transaction.TransactionDefinition} and
@@ -102,7 +103,8 @@
102103
* <p>This just serves as a hint for the actual transaction subsystem;
103104
* it will <i>not necessarily</i> cause failure of write access attempts.
104105
* A transaction manager which cannot interpret the read-only hint will
105-
* <i>not</i> throw an exception when asked for a read-only transaction.
106+
* <i>not</i> throw an exception when asked for a read-only transaction
107+
* but rather silently ignore the hint.
106108
* @see org.springframework.transaction.interceptor.TransactionAttribute#isReadOnly()
107109
*/
108110
boolean readOnly() default false;
@@ -111,10 +113,15 @@
111113
* Defines zero (0) or more exception {@link Class classes}, which must be
112114
* subclasses of {@link Throwable}, indicating which exception types must cause
113115
* a transaction rollback.
116+
* <p>By default, a transaction will be rolling back on {@link RuntimeException}
117+
* and {@link Error} but not on checked exceptions (business exceptions). See
118+
* {@link org.springframework.transaction.interceptor.DefaultTransactionAttribute#rollbackOn(Throwable)}
119+
* for a detailed explanation.
114120
* <p>This is the preferred way to construct a rollback rule (in contrast to
115121
* {@link #rollbackForClassName}), matching the exception class and its subclasses.
116-
* <p>Similar to {@link org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(Class clazz)}
122+
* <p>Similar to {@link org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(Class clazz)}.
117123
* @see #rollbackForClassName
124+
* @see org.springframework.transaction.interceptor.DefaultTransactionAttribute#rollbackOn(Throwable)
118125
*/
119126
Class<? extends Throwable>[] rollbackFor() default {};
120127

@@ -124,16 +131,17 @@
124131
* a transaction rollback.
125132
* <p>This can be a substring of a fully qualified class name, with no wildcard
126133
* support at present. For example, a value of {@code "ServletException"} would
127-
* match {@link javax.servlet.ServletException} and its subclasses.
134+
* match {@code javax.servlet.ServletException} and its subclasses.
128135
* <p><b>NB:</b> Consider carefully how specific the pattern is and whether
129136
* to include package information (which isn't mandatory). For example,
130137
* {@code "Exception"} will match nearly anything and will probably hide other
131138
* rules. {@code "java.lang.Exception"} would be correct if {@code "Exception"}
132139
* were meant to define a rule for all checked exceptions. With more unusual
133140
* {@link Exception} names such as {@code "BaseBusinessException"} there is no
134141
* need to use a FQN.
135-
* <p>Similar to {@link org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(String exceptionName)}
142+
* <p>Similar to {@link org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(String exceptionName)}.
136143
* @see #rollbackFor
144+
* @see org.springframework.transaction.interceptor.DefaultTransactionAttribute#rollbackOn(Throwable)
137145
*/
138146
String[] rollbackForClassName() default {};
139147

@@ -144,8 +152,9 @@
144152
* <p>This is the preferred way to construct a rollback rule (in contrast
145153
* to {@link #noRollbackForClassName}), matching the exception class and
146154
* its subclasses.
147-
* <p>Similar to {@link org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(Class clazz)}
155+
* <p>Similar to {@link org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(Class clazz)}.
148156
* @see #noRollbackForClassName
157+
* @see org.springframework.transaction.interceptor.DefaultTransactionAttribute#rollbackOn(Throwable)
149158
*/
150159
Class<? extends Throwable>[] noRollbackFor() default {};
151160

@@ -155,8 +164,9 @@
155164
* cause a transaction rollback.
156165
* <p>See the description of {@link #rollbackForClassName} for further
157166
* information on how the specified names are treated.
158-
* <p>Similar to {@link org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(String exceptionName)}
167+
* <p>Similar to {@link org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(String exceptionName)}.
159168
* @see #noRollbackFor
169+
* @see org.springframework.transaction.interceptor.DefaultTransactionAttribute#rollbackOn(Throwable)
160170
*/
161171
String[] noRollbackForClassName() default {};
162172

0 commit comments

Comments
 (0)