我正在使用 spring mvc 和休眠
@Controller
public class COACategoriesController {
protected static Logger log = Logger.getLogger(COACategoriesController.class);
@Resource(name="COACategoriesService")
private COACategoriesService obj_coacs;
@Resource(name="COAMaintenanceService")
private COAMaintenanceService obj_coams;
@RequestMapping(value = "/addCoaCategory", method = RequestMethod.POST)
public String addCoaCategory(@RequestParam("conCatName") String coaCatName, Model model) {
Date sysdate = null;
String Message="";
try{
sysdate = new Date();
COACategoriesModel model1 = new COACategoriesModel( coaCatName, 1, "", sysdate , 0);
COAMaintenanceModel account = new COAMaintenanceModel();
account.setDiscription("Test Description");
account.setCategoryId(model1);
Message="Fail-First";
obj_coacs.AddCOACategories(model1);
Message="Fail-Second";
obj_coams.AddCOAMaintenance (account);
Message="Add Successfully";
}catch(Exception ex){
log.error("Exception.."+ex);
model.addAttribute("success", Message);
}
return "fin/category";
}
}
当所有事务成功保存时,我如何手动提交事务,如果任何事务插入失败,则回滚 catch 块中的所有事务。?
我正在使用 spring mvc 和休眠