Spring与JDBC整合、事务处理
Spring的配置文件
public class PersonServiceBean implements PersonService { @Resource Private OtherService otherService ;@Transactional public void xxx(){ stmt.executeUpdate("update person set name='888' whereid=1"); otherService.update();//OtherService的update方法的事务传播属性为NESTED stmt.executeUpdate("delete from person where id=9"); }}
NESTED是一个比较特殊的属性,可以理解为事务的嵌套,就如上面的xxx方法是使用了事务的,也就是说一整个方法体属于一个事务,但是因为otherService.update被nested属性修饰了所以当这个方法出现异常而,其他操作没有出现异常的话,整个事务也会提交,除了otherService.update的事务不被提交