我想在功能上回滚事务说某某()回滚函数中的交易调用另一个函数
该XYZ调用另一个函数说ABC()内,它有它自己的事务TX。如果由于异常Abc()回退它的事务,因此xyz()中的事务也应该回滚。 如何在xyz()中回滚事务?
这是我的代码。
public String execute() throws Exception {
// viewReadOnly();
Session sf=null;
Transaction tx=null;
try {
sf = HibernateUtil.getSessionFactory().getCurrentSession();
tx = sf.getTransaction();
tx.begin();
//sosFile.setCmaId(1);
//sosFile.setSosFileId(1);
//sosFile.setHeadImage(new ImageService().readImageOldWay(headFile));
//sosFile.setFootImage(new ImageService().readImageOldWay(footFile));
//if(new ImageService().readImageOldWay(headFile) != null)
System.out.println("FLAG="+flag);
if(headFile!=null)
{
for (int i = 0; i < headFile.length; i++) {
if (headFile != null) {
sosOrder = new SOSCustomerOrderFile();
sosOrder.setCmaId(cmaId);
sosOrder.setFileData(new ImageService().readImageOldWay(headFile[i]));
sosOrder.setFileName(new File(sosorderfilename[i]).getName());
sosOrder.setSosStage(flag);
sf.saveOrUpdate(sosOrder);
}
}
}
if(footFile!=null)
{
for (int i = 0; i < footFile.length; i++) {
if (footFile != null) {
sosCheque.setCmaId(cmaId);
sosCheque.setFileData(new ImageService().readImageOldWay(footFile[i]));
sosCheque.setFileName(new File(soschequefilename[i]).getName());
sosCheque.setSosStage(flag);
sf.saveOrUpdate(sosCheque);
}
}
}
// tx.begin();
// sf.close();
/*Session sf1 = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx1 = sf1.getTransaction();
tx1.begin();*/
if (cheque_no_hidden != null || cheque_amount_hidden != null || cheque_bank_hidden != null || cheque_date_hidden != null) {
for (int i = 0; i < chequeCounter; i++) {
cheque_no = cheque_no_hidden.split(",");
cheque_amount = cheque_amount_hidden.split(",");
cheque_bank = cheque_bank_hidden.split(",");
cheque_date = cheque_date_hidden.split(",");
SOSChequeDetails sosChequeD = new SOSChequeDetails();
sosChequeD.setChequeNo(cheque_no[i]);
sosChequeD.setChequeAmount(cheque_amount[i]);
sosChequeD.setChequeBank(cheque_bank[i]);
sosChequeD.setChequeDate(cheque_date[i]);
sosChequeD.setCmaId(cmaId);
sosChequeD.setSosStage(flag);
sf.saveOrUpdate(sosChequeD);
// tx1.begin();
// sf1.close();
}
}
if(saveSOSValue.saveSOS(sosValues, cmaId,flag,sf,tx))
{
sosValues.setFlag(1);
}
else
{
sosValues.setFlag(2);
}
if(flag.equalsIgnoreCase("sosSUBMIT"))
{
CmaDetails cmaD = (CmaDetails) sf.get(CmaDetails.class, cmaId);
/* for(int j=0;j<5;j++){
LeaveManagementManager manager=new LeaveManagementManager();
Userinfo userinfoLeave=manager.getUserInfoObjforsos(sosWorkflow_status);
workflow.setFromDesignation(userinfoLeave.getWorkflowdesignation().getWorkflowDesignationId());
List<Workflow> workflowListTemp=new ArrayList<Workflow>();
workflowListTemp=(new WorkflowService().performAction(workflow));
if(userinfoLeave.getOutOfOffice()!=null && userinfoLeave.getOutOfOffice().equals("OOO")){
date.setSeconds(date.getSeconds()+1);
wfs=makeEntryInWorkflow(sdm,formater,now, date, workflowListTemp, cmaDetails, query, i, ToEmailIdTemp, ToEmailId,wfs,null);
}else{
j=5;
}
}*/
boolean decideRollback=approveSOSvalue.ApprovalSOSWorkflow(sosWorkflow_status,sosValues,cmaD,"create",1,"flag");
if(decideRollback==false){
tx.rollback();
}
}
} catch (Exception e) {
if (tx!=null) tx.rollback();
e.printStackTrace();
}
viewDocuments();
viewCheques();
/* ComplianceCMA complianceCMA = new ComplianceCMA();
cmaDetails = complianceCMA.getCma(cmaId);
cmaDetails.setStage(Constants.STAGE_SOS_UPLOAD);
UpdateCMA updateStage = new UpdateCMA();
updateStage.performAction(cmaDetails);*/
ViewSOSDetails viewsos=new ViewSOSDetails();
viewsos.home();
return SUCCESS;
}
这个函数调用
public boolean ApprovalSOSWorkflow(SOSWorkflow_status sosWorkflowstatuscomment,SOSValues sosValues,CmaDetails cmaId,String Action,int bpaID,String flag)
功能。 请帮忙。
请将'edits'添加到上面的原始问题中。评论并不意味着代码包。 – Nazgul 2014-12-11 06:08:06
我已添加我的代码。 我得到另一个异常说我的交易没有成功开始。 – iamP 2014-12-11 06:34:13