Multiple such rules can be applied to determine whether a transaction should commit or rollback after an exception has been thrown.
Each rule is based on an exception type or exception pattern, supplied via
RollbackRuleAttribute(Class) or RollbackRuleAttribute(String),
respectively.
When a rollback rule is defined with an exception type, that type will be
used to match against the type of a thrown exception and its super types,
providing type safety and avoiding any unintentional matches that may occur
when using a pattern. For example, a value of
jakarta.servlet.ServletException.class will only match thrown exceptions
of type jakarta.servlet.ServletException and its subclasses.
When a rollback rule is defined with an exception pattern, the pattern can
be a fully qualified class name or a substring of a fully qualified class name
for an exception type (which must be a subclass of Throwable), with no
wildcard support at present. For example, a value of
"jakarta.servlet.ServletException" or "ServletException" will
match jakarta.servlet.ServletException and its subclasses.
See the javadocs for
@Transactional
for further details on rollback rule semantics, patterns, and warnings regarding
possible unintentional matches with pattern-based rules.
NoRollbackRuleAttribute
| Modifier and Type | Field and Description |
|---|---|
| private final String | exceptionPattern
Exception pattern: used when searching for matches in a thrown exception's class hierarchy based on names of exceptions, with zero type safety and potentially resulting in unintentional matches for similarly named exception types and nested exception types. |
| private final Class | exceptionType
Exception type: used to ensure type safety when searching for matches in a thrown exception's class hierarchy. |
| public static final RollbackRuleAttribute |
| Access | Constructor and Description |
|---|---|
| public | RollbackRuleAttribute(Class<?>
exception type; must be exceptionType)Throwable or a subclass
of ThrowableCreate a new instance of the |
| public | RollbackRuleAttribute(String
the exception name pattern; can also be a fully
package-qualified class name exceptionPattern)Create a new instance of the |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
the reference object with which to compare. other)Overrides java. |
| public int | |
| private int | |
| public String | |
| public int | |
| public String |
| exceptionPattern | back to summary |
|---|---|
| private final String exceptionPattern Exception pattern: used when searching for matches in a thrown exception's class hierarchy based on names of exceptions, with zero type safety and potentially resulting in unintentional matches for similarly named exception types and nested exception types. | |
| exceptionType | back to summary |
|---|---|
| private final Class<? extends Throwable> exceptionType Exception type: used to ensure type safety when searching for matches in a thrown exception's class hierarchy.
| |
| ROLLBACK_ON_RUNTIME_EXCEPTIONS | back to summary |
|---|---|
| public static final RollbackRuleAttribute ROLLBACK_ON_RUNTIME_EXCEPTIONS The rollback rule for
| |
| RollbackRuleAttribute | back to summary |
|---|---|
| public RollbackRuleAttribute(Class<?> exceptionType) Create a new instance of the This is the preferred way to construct a rollback rule that matches the supplied exception type and its subclasses with type safety. See the javadocs for
| |
| RollbackRuleAttribute | back to summary |
|---|---|
| public RollbackRuleAttribute(String exceptionPattern) Create a new instance of the See the javadocs for
For improved type safety and to avoid unintentional matches, use
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| getDepth | back to summary |
|---|---|
| public int getDepth(Throwable exception) Return the depth of the superclass matching, with the following semantics.
When comparing roll back rules that match against a given exception, a rule
with a lower matching depth wins. For example, a direct match ( When constructed with an exception pattern via | |
| getDepth | back to summary |
|---|---|
| private int getDepth(Class<?> exceptionType, int depth) | |
| getExceptionName | back to summary |
|---|---|
| public String getExceptionName() Get the configured exception name pattern that this rule uses for matching.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |