java代码中添加事务_Java代码数据库操作事务

这是一种使用非常方便的实现事务特性的代码段,其中try-catch代码块中的代码执行一次保存操作提交一次事务

//添加事务

Object r = new NewTransactionTemplate().execute(new TransactionCallback() {

ArpInvoiceModel tempModel = new ArpInvoiceModel();

@Override

public Object doInTransaction(TransactionStatus arg0) {

//保存

try {

tempModel = arpInvoiceManager.saveInvoicegenerate(arpInvoiceModel, details, fids, "", "", null, tempModel, thisOperateSign, "","");

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return tempModel;

}

});

仅供参考;

你可能感兴趣的:(java代码中添加事务)