在用jfinal声明式事务的时候不能主动回滚,报错是故意的,发现不能回滚是不是哪里写错了!下面是我的代码
@Before(Tx.class) public void saveTop(EnPtype ptype, EnTop enTop, Ret ret, Integer oldTopID){ if (ptype.getProID() == null) { ptype.save(); } if (oldTopID != null && oldTopID > 0) { String sql = "UPDATE en_top SET topstate = ? WHERE topID = ?"; Db.update(sql, 2, oldTopID); } String topName = ptype.getPTypeFrom() + "-" + ptype.getPTypeName(); enTop.setTopName(topName); enTop.setProjectType(ptype.getProID()); enTop.save(); String[] stageName = {"开始阶段", "施工阶段", "收尾阶段"}; List<EnTopstage> stageList = new ArrayList<>(); for (int i = 0; i < stageName.length; i++) { EnTopstage topstage = new EnTopstage(); topstage.setStageName(stageName[i]); topstage.setTopID(enTop.getTopID()); topstage.save(); stageList.add(topstage); } String s1 = "s"; Integer.valueOf(s1); List<EnTopnode> topData = (List<EnTopnode>) ret.get("enTopNodeList"); //保存节点 for (EnTopnode topnode : topData) { String last = topnode.getNodeLast(); String l = ""; for (String s : last.split(",")) { if (s == "") continue; l += topData.get(Integer.parseInt(s)).getNodeID() + ","; } Integer nodeStage = topnode.getNodeStage()-1; if (nodeStage >= 0) { topnode.setNodeStage(stageList.get(nodeStage).getStageID()); } topnode.setNodeLast(l); topnode.setTopID(enTop.getTopID()); topnode.save(); } //更新节点 写入后续节点ID for (EnTopnode topnode : topData) { String next = topnode.getNodeNext(); String n = ""; for (String s : next.split(",")) { if (s == "") continue; n += topData.get(Integer.parseInt(s)).getNodeID() + ","; } topnode.setNodeNext(n); topnode.update(); } List<List<EnTopnodeoption>> option = (List<List<EnTopnodeoption>>) ret.get("option"); for (List<EnTopnodeoption> list : option) { if (list == null) continue; for (int i = 0; i < list.size(); i++) { EnTopnodeoption topnodeoption = list.get(i); Integer nodeID = topnodeoption.getNodeID(); topnodeoption.setNodeID(topData.get(nodeID).getNodeID()); topnodeoption.setOpOrder(i); topnodeoption.save(); } } }