1,@Transactional 只支持public 方法
2,自调用事务出现的情况:
@Service
public class Txservice {
@Transactional
public void saveA(A a){
dao.saveA(a);
}
@Transactional
public void saveB(B b){
dao.saveB(b);
}
public void saveAB(A a,B b) {
saveA(A a);
saveB(B b);
}
}
saveAB方法事务会失效,spring中事务是基于AOP实现,当saveB方法出现异常,saveA不会出现回滚.
同样以下情况也会出现自调用事务失效
@Service
public class Txservice {
@Transactional
public void saveA(A a){
dao.saveA(a);
}
@Transactional (propagation = Propagation.REQUIRES_NEW)
public void saveB(B b){
dao.saveB(b);
}
@Transactional
public void saveAB(A a,B b) {
saveA(A a);
saveB(B b);
}
}