当父方法中没有捕获异常时:同一个类中,父方法有事务发生异常,不管子方法是否有事务都会子方法都会回滚;不通类中调用,父方法有事务发生异常,子方法有事务且事务传播性为REQUIRES_NEW,子方法不会回滚父方法回滚,子方法事务传播性默认require或者子方法没有事务,则父方法、子方法一起回滚,
多数据源,事务注解必须指定value值,
2个事务方法在一个类里面,互相调用。注解都不起作用。
test:
@Transactional(value = "salesInvoiceTransactionManager",propagation = Propagation.REQUIRES_NEW)
public void update(){
com.yao.invoice.api.model.bean.invoiceInfo.InvoiceNoticeMessageBean invoiceNoticeMessageBean=new InvoiceNoticeMessageBean();
invoiceNoticeMessageBean.setPhoneContent("test");
invoiceNoticeMessageBean.setChildOrderId("aaa");
invoiceNoticeMessageDao.insert(invoiceNoticeMessageBean);
}
}
public class TestTransaction{
@Autowired
private InvoiceNoticeMessageDao invoiceNoticeMessageDao;
@Autowired
private InvoiceSplitServiceImpl invoiceSplitServiceImpl;
@Transactional(value = "salesInvoiceTransactionManager",propagation = Propagation.REQUIRES_NEW)
public void insert(){
com.yao.invoice.api.model.bean.invoiceInfo.InvoiceNoticeMessageBean invoiceNoticeMessageBean=new InvoiceNoticeMessageBean();
invoiceNoticeMessageBean.setPhoneContent("test");
invoiceNoticeMessageBean.setChildOrderId("aaa");
invoiceNoticeMessageDao.insert(invoiceNoticeMessageBean);
}
/**
* 测试事务,当父方法有事务发生异常,不管子方法是否有事务都会子方法都会回滚,当父方法还有父方法
*/
@Transactional(value = "salesInvoiceTransactionManager")
public void updateLoad(){
invoiceSplitServiceImpl.update();
InvoiceProductFilterBean filterBean=new InvoiceProductFilterBean();
filterBean.setGoodsName("test");
filterBean.setId(21L);
invoiceProductFilterDao.updateByPrimaryKeySelective(filterBean);
throw new RuntimeException("aa");
}
}