Concept
@Transactional runs a method inside one database transaction, committing at the end and rolling back on an unchecked exception. Service methods that change several rows need it so partial updates never persist.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Transactions doing its job.
@Service
public class TransferService {
@Transactional
public void transfer(UUID from, UUID to, long cents) {
var source = accounts.findById(from).orElseThrow();
var target = accounts.findById(to).orElseThrow();
source.withdraw(cents); // throws -> whole transaction rolls back
target.deposit(cents);
}
}Calling a @Transactional method from another method of the same class. The call bypasses the proxy, so no transaction starts. Put the transactional method on a bean that is called from outside.
Your roadmap puts these before Transactions, unless you already know them.
Once a session shows you understand Transactions, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
Topics that build on Transactions.