【发布时间】:2019-07-27 00:26:09
【问题描述】:
@Service
@Transactional
public class OrderService {
//Implemented with JdbcTemplate (no ORM)
//Both Dao use the same DataSource
private AccountDao accountDao;
private OrderDao orderDao;
public void update(int accountId){
//Get account and do some calculation (simplifed version here)
Account account = accountDao.findByid(accountId)
int newAmount = account.getAmoount * 100;
//Update account table
accountDao.updateAmount(accountId, newAmount);
//Insert new order
Order order = ....
orderDao.save(order);
}
}
在上面的代码中,如果更新的帐户行被另一个事务修改,我想回滚accountDao.updateAmount 和orderDao.save。
【问题讨论】:
标签: java sql spring jdbc transactions