@Transactional ห่อ method ไว้ใน transaction ของฐานข้อมูล: Spring เปิด transaction ก่อน method ทำงาน และ commit เมื่อ method คืนค่าตามปกติ — หรือ rollback หากมีการโยน exception เบื้องหลังมันคือ AOP proxy ซึ่งเป็นต้นตอของ gotcha ส่วนใหญ่
การใช้งานพื้นฐาน
{
{
accounts.debit(from, amount);
accounts.credit(to, amount);
}
}
