From 5d325ca0fcbfcad87afa49049994992042b2c178 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Tue, 19 Aug 2025 13:32:35 +0200 Subject: [PATCH] Improve wording for transactional rollback rule semantics Closes gh-35346 --- .../transaction/declarative/rolling-back.adoc | 12 +++++++----- .../transaction/annotation/Transactional.java | 9 ++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/framework-docs/modules/ROOT/pages/data-access/transaction/declarative/rolling-back.adoc b/framework-docs/modules/ROOT/pages/data-access/transaction/declarative/rolling-back.adoc index a16f4985f2d..42ad16cd0e9 100644 --- a/framework-docs/modules/ROOT/pages/data-access/transaction/declarative/rolling-back.adoc +++ b/framework-docs/modules/ROOT/pages/data-access/transaction/declarative/rolling-back.adoc @@ -86,11 +86,13 @@ rollback rules may be configured via the `rollbackFor`/`noRollbackFor` and `rollbackForClassName`/`noRollbackForClassName` attributes, which allow rules to be defined based on exception types or patterns, 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 type – for example, via `rollbackFor` – +that type will be used to match against the type of a thrown exception. Specifically, +given a configured exception type `C`, a thrown exception of type `T` will be considered +a match against `C` if `T` is equal to `C` or a subclass of `C`. This provides type +safety and avoids 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 diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/Transactional.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/Transactional.java index f1f9a6652a2..da826186304 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/Transactional.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/Transactional.java @@ -56,9 +56,12 @@ import org.springframework.transaction.TransactionDefinition; * {@link #rollbackForClassName}/{@link #noRollbackForClassName}, which allow * rules to be specified as types or patterns, 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 a rollback rule is defined with an exception type — for example, + * via {@link #rollbackFor} — that type will be used to match against the + * type of a thrown exception. Specifically, given a configured exception type + * {@code C}, a thrown exception of type {@code T} will be considered a match + * against {@code C} if {@code T} is equal to {@code C} or a subclass of {@code C}. + * This provides type safety and avoids any unintentional matches that may occur * when using a pattern. For example, a value of * {@code jakarta.servlet.ServletException.class} will only match thrown exceptions * of type {@code jakarta.servlet.ServletException} and its subclasses.