SlideShare a Scribd company logo
VictorRentea.ro
@Transactional
1 JPA – Runtime
@Transactional(propagation = Propagation.SUPPORTS)
public class EmployeeService {
public void getEmployee(long employeeId) { ... }
@Transactional(propagation = Propagation.MANDATORY)
public void createEmployee(Employee employee) { ... }
}
Works via an AOP Proxy wrapping the EmployeeService
VictorRentea.ro
@Transactional  Life
2 JPA – Runtime
Account
Service
Account
Repo
Transfer
Service
payEnelBill()
getAccount
SUPPORTS
payBill()
COMMIT
MANDATORY
@Transactional(propagation = REQUIRED)
Persistence
Context
@PersistenceContext
private EntityManager em;
Inject an EntityManager proxy
em.find(...)
em.find(...)
VictorRentea.ro3 JPA – Runtime
class B {
@Transactional(propag=???)
public void b() { ... }
}
@Autowired private B b;
public void a() { b.b(); }
How does it work?
proxy
@Transactional
I can do more stuff
before calling the real b()
VictorRentea.ro
Propagation
4 JPA – Runtime
supports
required=default
requires new
mandatory
not supported
never
nested !
class B {
@Transactional(propag=???)
public void b() { ... }
}
@Autowired private B b;
public void a() { b.b(); }
existing Tx no Tx
a b a b
pause Tx
ex
ex
Caller Tx
New Tx
No Tx
@Transactional
on ex, only this is lost
(SAVEPOINT)
VictorRentea.ro
PC2
REQUIRES_NEW
@Transactional  Life
5 JPA – Runtime
Account
Service
Account
Repo
Transfer
Service
payEnelBill()
getAccount
SUPPORTS
payBill()
ROLLBACK
MANDATORY
REQUIRED
Persistence
Context
em.find(...)
Error
Repo
@PersistenceContext
private EntityManager em;
try {
} catch (e) {
}
REQUIRED
em.persist(error)
tx.setRollbackOnly()
persistError()
COMMIT
Ex
VictorRentea.ro
Throw a RuntimeException from a method, if:
- The method allows the Tx to enter, and
- The method is aspected by TransactionInterception
When is a method Tx-aspected?
- If there is any @Transactional in that class ?
How do you kill a @Tx ?
6 JPA – Runtime
This one actually kills the Tx
Can be customized: @Transactional(rollbackFor=…, noRollbackFor=…)

More Related Content

PPTX
Clean Pragmatic Architecture - Avoiding a Monolith
PPT
Spring Core
PPTX
Java 8 Lambda and Streams
PPTX
Python/Flask Presentation
PPTX
Java 8 presentation
PPTX
Ajax
PDF
Java Design Patterns Tutorial | Edureka
PDF
Testing with JUnit 5 and Spring - Spring I/O 2022
Clean Pragmatic Architecture - Avoiding a Monolith
Spring Core
Java 8 Lambda and Streams
Python/Flask Presentation
Java 8 presentation
Ajax
Java Design Patterns Tutorial | Edureka
Testing with JUnit 5 and Spring - Spring I/O 2022

What's hot (20)

PPTX
JavaFX Presentation
PDF
Java 8 Lambda Expressions
PPTX
Jdbc ppt
PDF
Java Course 8: I/O, Files and Streams
PPTX
Advance Java Topics (J2EE)
PDF
Collections In Java
PPSX
Exception Handling
PPTX
Java Server Pages
PPTX
Multithreading in java
PDF
jQuery for beginners
PPTX
Multithreading in java
PPTX
Java Server Pages(jsp)
PDF
Java exception handling ppt
PPTX
Java GC
PPTX
MULTI THREADING IN JAVA
PPT
Spring Boot in Action
PPTX
Strings in Java
PDF
Clean pragmatic architecture @ devflix
JavaFX Presentation
Java 8 Lambda Expressions
Jdbc ppt
Java Course 8: I/O, Files and Streams
Advance Java Topics (J2EE)
Collections In Java
Exception Handling
Java Server Pages
Multithreading in java
jQuery for beginners
Multithreading in java
Java Server Pages(jsp)
Java exception handling ppt
Java GC
MULTI THREADING IN JAVA
Spring Boot in Action
Strings in Java
Clean pragmatic architecture @ devflix
Ad

Similar to Spring @Transactional Explained (20)

PDF
Demoiselle 2.0 no JavaOne Brasil 2010
PDF
softshake 2014 - Java EE
PPTX
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
PDF
Ejb3 Dan Hinojosa
ODP
Finagle and Java Service Framework at Pinterest
PPT
Rich Enterprise Applications with JavaFX
PPT
Swiss army knife Spring
PDF
Annotations Processor Tools (APT)
PPTX
An Introduction to WebWorker - 01.26.12
ODP
Ruslan Platonov - Transactions
ODP
KEY
The use of Symfony2 @ Overblog
PPT
比XML更好用的Java Annotation
PDF
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
PDF
S313937 cdi dochez
ODP
Jpa buenas practicas
ODP
JPA Best Practices
ODP
jBPM5 in action - a quickstart for developers
PDF
Saving lives with rx java
PDF
May 2010 - RestEasy
Demoiselle 2.0 no JavaOne Brasil 2010
softshake 2014 - Java EE
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Ejb3 Dan Hinojosa
Finagle and Java Service Framework at Pinterest
Rich Enterprise Applications with JavaFX
Swiss army knife Spring
Annotations Processor Tools (APT)
An Introduction to WebWorker - 01.26.12
Ruslan Platonov - Transactions
The use of Symfony2 @ Overblog
比XML更好用的Java Annotation
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
S313937 cdi dochez
Jpa buenas practicas
JPA Best Practices
jBPM5 in action - a quickstart for developers
Saving lives with rx java
May 2010 - RestEasy
Ad

More from Victor Rentea (20)

PDF
Top REST API Desgin Pitfalls @ Devoxx 2024
PDF
The Joy of Testing - Deep Dive @ Devoxx Belgium 2024
PDF
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
PDF
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
PDF
Microservice Resilience Patterns @VoxxedCern'24
PDF
Distributed Consistency.pdf
PDF
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
PDF
Testing Microservices @DevoxxBE 23.pdf
PPTX
From Web to Flux @DevoxxBE 2023.pptx
PPTX
Test-Driven Design Insights@DevoxxBE 2023.pptx
PDF
Profiling your Java Application
PPTX
OAuth in the Wild
PPTX
The tests are trying to tell you something@VoxxedBucharest.pptx
PPTX
Vertical Slicing Architectures
PDF
Software Craftsmanship @Code Camp Festival 2022.pdf
PDF
Unit testing - 9 design hints
PPTX
Extreme Professionalism - Software Craftsmanship
PDF
Clean architecture - Protecting the Domain
PDF
Refactoring blockers and code smells @jNation 2021
PDF
Hibernate and Spring - Unleash the Magic
Top REST API Desgin Pitfalls @ Devoxx 2024
The Joy of Testing - Deep Dive @ Devoxx Belgium 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Microservice Resilience Patterns @VoxxedCern'24
Distributed Consistency.pdf
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Testing Microservices @DevoxxBE 23.pdf
From Web to Flux @DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptx
Profiling your Java Application
OAuth in the Wild
The tests are trying to tell you something@VoxxedBucharest.pptx
Vertical Slicing Architectures
Software Craftsmanship @Code Camp Festival 2022.pdf
Unit testing - 9 design hints
Extreme Professionalism - Software Craftsmanship
Clean architecture - Protecting the Domain
Refactoring blockers and code smells @jNation 2021
Hibernate and Spring - Unleash the Magic

Recently uploaded (20)

PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administraation Chapter 3
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Essential Infomation Tech presentation.pptx
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
history of c programming in notes for students .pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Digital Strategies for Manufacturing Companies
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Transform Your Business with a Software ERP System
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Reimagine Home Health with the Power of Agentic AI​
Odoo POS Development Services by CandidRoot Solutions
System and Network Administraation Chapter 3
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
How to Choose the Right IT Partner for Your Business in Malaysia
Softaken Excel to vCard Converter Software.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Essential Infomation Tech presentation.pptx
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
history of c programming in notes for students .pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Digital Strategies for Manufacturing Companies
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Transform Your Business with a Software ERP System
How to Migrate SBCGlobal Email to Yahoo Easily
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Reimagine Home Health with the Power of Agentic AI​

Spring @Transactional Explained

  • 1. VictorRentea.ro @Transactional 1 JPA – Runtime @Transactional(propagation = Propagation.SUPPORTS) public class EmployeeService { public void getEmployee(long employeeId) { ... } @Transactional(propagation = Propagation.MANDATORY) public void createEmployee(Employee employee) { ... } } Works via an AOP Proxy wrapping the EmployeeService
  • 2. VictorRentea.ro @Transactional  Life 2 JPA – Runtime Account Service Account Repo Transfer Service payEnelBill() getAccount SUPPORTS payBill() COMMIT MANDATORY @Transactional(propagation = REQUIRED) Persistence Context @PersistenceContext private EntityManager em; Inject an EntityManager proxy em.find(...) em.find(...)
  • 3. VictorRentea.ro3 JPA – Runtime class B { @Transactional(propag=???) public void b() { ... } } @Autowired private B b; public void a() { b.b(); } How does it work? proxy @Transactional I can do more stuff before calling the real b()
  • 4. VictorRentea.ro Propagation 4 JPA – Runtime supports required=default requires new mandatory not supported never nested ! class B { @Transactional(propag=???) public void b() { ... } } @Autowired private B b; public void a() { b.b(); } existing Tx no Tx a b a b pause Tx ex ex Caller Tx New Tx No Tx @Transactional on ex, only this is lost (SAVEPOINT)
  • 5. VictorRentea.ro PC2 REQUIRES_NEW @Transactional  Life 5 JPA – Runtime Account Service Account Repo Transfer Service payEnelBill() getAccount SUPPORTS payBill() ROLLBACK MANDATORY REQUIRED Persistence Context em.find(...) Error Repo @PersistenceContext private EntityManager em; try { } catch (e) { } REQUIRED em.persist(error) tx.setRollbackOnly() persistError() COMMIT Ex
  • 6. VictorRentea.ro Throw a RuntimeException from a method, if: - The method allows the Tx to enter, and - The method is aspected by TransactionInterception When is a method Tx-aspected? - If there is any @Transactional in that class ? How do you kill a @Tx ? 6 JPA – Runtime This one actually kills the Tx Can be customized: @Transactional(rollbackFor=…, noRollbackFor=…)