读书人

Spring与JDBC调整、事务处理

发布时间: 2012-11-03 10:57:44 作者: rapoo

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的事务不被提交

读书人网 >其他数据库

热点推荐