一個很棘手的問題,做的是XML數據導入功能,數據無法提交,也沒有出現任何異常,在控制臺里面都沒有出現插入語句,但如果我單純的提交一個對象,就是普通的提交數據功能,也是在用一個事務里面,就能提交數據。代碼如下,若代碼有問題,請指出。/** * 開始導入 * * @param xmlList * XML文件絕對路徑數組 * @return */ private int sendImport(String[] xmlList) { Session session = null; try { session = Database.getSession(); Session xmlSession = session.getSession(EntityMode.DOM4J); session.beginTransaction(); for (int i = 0; i < xmlList.length; i++) { inportByXML(xmlSession, xmlList[i]); } session.getTransaction().commit(); } catch (Exception e) { session.getTransaction().rollback(); Database.endTransaction(true); return ERROR_IMPORT; } finally { session.close(); } return IMPORT; } /** * 存入數據庫 * * @param xmlSession * @param xmlPath * XML絕對路徑 * @throws DocumentException */ private void inportByXML(Session xmlSession, String xmlPath) throws DocumentException { SAXReader reader = new SAXReader(); Document document = reader.read(xmlPath); List entities = document.getRootElement().content(); Iterator it = entities.iterator(); while (it.hasNext()) { Node item = (Node) it.next(); xmlSession.save(c.getName(), item); } }
添加回答
舉報
0/150
提交
取消