Understanding Spring Transaction Propagation Types

💡 Spring Transaction Propagation — What Really Happens When Transactions Call Each Other In my last post, I shared why a @Transactional method might not even start a transaction. This time, let’s go one level deeper — into propagation types, which define how transactions behave when one method calls another. 👇 1️⃣ REQUIRED (default) Joins the current transaction or creates a new one if none exists. → Most common — perfect for simple service-to-repository calls. 2️⃣ REQUIRES_NEW Always starts a new transaction, suspending the current one. → Great for independent operations like logging or audit trails. 3️⃣ SUPPORTS Runs within a transaction if one exists; otherwise, runs non-transactional. → Useful for read-only methods that can work with or without transactions. 4️⃣ MANDATORY Throws an exception if there’s no existing transaction. → Enforces strict transactional context. 5️⃣ NOT_SUPPORTED Suspends the active transaction and runs non-transactional. 6️⃣ NEVER Throws an exception if a transaction exists. 7️⃣ NESTED Creates a sub-transaction that can roll back independently (requires JDBC save-points). 🧠 Real-world example: In a payment system, you might use REQUIRES_NEW for saving audit logs — even if the main payment transaction fails, the log should still commit. Understanding propagation isn’t just academic — it defines how your data behaves in real-world failures. It’s the difference between safe rollbacks and invisible inconsistencies. Which propagation type do you use most often — and why? 👇 #java #springboot #transactionmanagement #hibernate #backenddevelopment #programming #softwareengineering #transactions

  • diagram

To view or add a comment, sign in

Explore content categories