java 代码
- public void deleteAllBugInTestReport(Integer testReportId) throws DaoException {
- try {
- Session session = HibernateUtil.getSession();
- StringBuilder selectBugRelation = new StringBuilder("select br.id from BugRelation as br, Bug as b ").append(
- "where ((br.fromId=b.bugId) or (br.toId=b.bugId)) ").append(
- "and b.testReportId = ").append(testReportId).append(")");
- Debug.logInfo(selectBugRelation.toString(),module);
- doDelete(session, session.createQuery(selectBugRelation.toString()).list(), "delete BugRelation where ");
- StringBuilder selectBugFieldHistory = new StringBuilder("select bfh.id from BugFieldHistory as bfh, BugHistory as bh, Bug as b ").append(
- "where bfh.bugHistoryId = bh.id and bh.bugId = b.bugId ").append(
- " and b.testReportId = ").append(testReportId).append(")");
- Debug.logInfo(selectBugFieldHistory.toString(), module);
- doDelete(session, session.createQuery(selectBugFieldHistory.toString()).list(), "delete BugFieldHistory where ");
- StringBuilder selectBugHistory = new StringBuilder(
- "select bh.id from BugHistory as bh, Bug as b ").append(
- "where bh.bugId = b.bugId and b.testReportId = ").append(testReportId).append(")");
- Debug.logInfo(selectBugHistory.toString(), module);
- doDelete(session, session.createQuery(selectBugHistory.toString()).list(), "delete BugHistory where ");
- StringBuilder deleteBug = new StringBuilder(
- "delete Bug where testReportId = ").append(testReportId);
- Debug.logInfo(deleteBug.toString(), module);
- session.createQuery(deleteBug.toString()).executeUpdate();
- } catch (Exception e) {
- throw new DaoException(e);
- }
- }
上面就是批量删除的操作。实体工具真的不行。在性能上有要求的地方,我觉得还真的不如用JDBC好。