Home > Back-end >  Effective springboot @ transactional don't update data not rolled back
Effective springboot @ transactional don't update data not rolled back

Time:11-22

The code below
Package com. HSP. Adapter. Service. Impl;

import java.util.Arrays;
import java.util.List;
Import the Java. Util. The Map;

import org.springframework.beans.factory.annotation.Autowired;
The import org. Springframework. Stereotype. Service;
The import org. Springframework. Transaction. The annotation. Transactional;
The import org. Springframework. Transaction. The interceptor. TransactionAspectSupport;

The import com. HSP. Adapter. Dao. ClinicDispensingMapper;

The import net. Sf. Json. JSONObject;

@ Service
Public class ClinicDispensingServiceImpl {

The @autowired
Private ClinicDispensingMapper dispensingmapper;

//update the dispensing state
@ Transactional (rollbackFor={Exception. Class})
Public String dispensingupdate (String param, String docker_id) {
JSONObject body=new JSONObject ();
List List=Arrays. AsList (param. Split (", "));
List Clinic_costlist=dispensingmapper. Queryclinic_cost_id (list);
If (clinic_costlist!=null& & Clinic_costlist. The size () & gt; 0 {
List Clinic_costdetlist=dispensingmapper. Queryclinic_costdet (clinic_costlist);
If (clinic_costdetlist!=null& & Clinic_costdetlist. The size () & gt; 0 {
//traverse the updates on the dispensing table
Try {

Dispensingmapper. Updateclinic_cost (clinic_costdetlist);
//update the drug IO table drug_io
Dispensingmapper. Updatedrug_io (docker_id clinic_costdetlist);
For (Map The map: clinic_costdetlist) {
Map Drug_stockdet=dispensingmapper. Querydrug_stockdet (map. Get (" item_id "). The toString (), map. Get (" exedep_id "). The toString (), map. Get (" num "). The toString ());
//if (drug_stockdet!=null& & Drug_stockdet. The size () & gt; 0 {
//update the stock list drug_stockdet
Dispensingmapper. Updatedrug_stockdet (map. Get (" num "). The toString (), drug_stockdet. Get (" id "). The toString ());//cycle is an error for the seventh time changed data before did not roll back
//update the schedule of drug IO drug_iodetail
Map Drug_iodetail=dispensingmapper. Querydrug_iodetail (map. Get (" id "). The toString ());
Dispensingmapper. Updatedrug_iodetail (drug_stockdet drug_iodetail. Get (" id "). The toString ());
//update fee itemizations clinic_costdet
Dispensingmapper. Updateclinic_costdet (map. Get (" id "). The toString ());
//}
}
} the catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
//update the charge for the main table clinic_cost
} else {
Body. The put (" result ", 200);
Body. The put (" info ", "failed to query");
Return to the body. The toString ();
}
} else {
Body. The put (" result ", 200);
Body. The put (" info ", "failed to query");
Return to the body. The toString ();
}
Body. The put (" result ", 200);
Body. The put (" info ", "success");
Return to the body. The toString ();
}


}

CodePudding user response:

 
@ Transactional (rollbackFor={Exception. Class})
Public String dispensingupdate (String param, String docker_id) {
JSONObject body=new JSONObject ();
List List=Arrays. AsList (param. Split (", "));
List Clinic_costlist=dispensingmapper. Queryclinic_cost_id (list);
If (clinic_costlist!=null& & Clinic_costlist. The size () & gt; 0 {
List Clinic_costdetlist=dispensingmapper. Queryclinic_costdet (clinic_costlist);
If (clinic_costdetlist!=null& & Clinic_costdetlist. The size () & gt; 0 {
//traverse the updates on the dispensing table
Try {
Dispensingmapper. Updateclinic_cost (clinic_costdetlist);
//update the drug IO table drug_io
Dispensingmapper. Updatedrug_io (docker_id clinic_costdetlist);
For (Map The map: clinic_costdetlist) {
Map Drug_stockdet=dispensingmapper. Querydrug_stockdet (map. Get (" item_id "). The toString (), map. Get (" exedep_id "). The toString (), map. Get (" num "). The toString ());
//if (drug_stockdet!=null& & Drug_stockdet. The size () & gt; 0 {
//update the stock list drug_stockdet
Dispensingmapper. Updatedrug_stockdet (map. Get (" num "). The toString (), drug_stockdet. Get (" id "). The toString ());//cycle is an error for the seventh time changed data before did not roll back
//update the schedule of drug IO drug_iodetail
Map Drug_iodetail=dispensingmapper. Querydrug_iodetail (map. Get (" id "). The toString ());
Dispensingmapper. Updatedrug_iodetail (drug_stockdet drug_iodetail. Get (" id "). The toString ());
//update fee itemizations clinic_costdet
Dispensingmapper. Updateclinic_costdet (map. Get (" id "). The toString ());
//}
}
} the catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
//update the charge for the main table clinic_cost
} else {
Body. The put (" result ", 200);
Body. The put (" info ", "failed to query");
Return to the body. The toString ();
}
} else {
Body. The put (" result ", 200);
Body. The put (" info ", "failed to query");
Return to the body. The toString ();
}
Body. The put (" result ", 200);
Body. The put (" info ", "success");
Return to the body. The toString ();
}

Method calls in the other if there is a transaction annotations (query) method

CodePudding user response:

reference 1/f, street vendors reply:
 
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related