有两张表,一张表是AdrReport,一张表是AppriseInfo,我在页面上取得了AdrReport表中的详细信息,同时也取到了AppriseInfo表中的一个字段AppraiseContent的值.
现在的问题是我在删除AdrReport表中信息的同时,没有删除掉AppriseInfo表中字段AppraiseContent的值.如何实现这样的删除操作,AdrReport表中有一个id是自动增长的,是主键,
是通过id来删除的,AppriseInfo表中也是有一个id是主键,还有一个reportId字段,就是对应AdrReport表中的id,也就是reportId是AdrReport表中id的外键.
当我在删除AdrReport表中信息时,同时也要删除掉AppriseInfo表中的信息,这一步该如何实现,非常的谢谢!
删除的方法我在action中是这样写的:        public ActionForward delReportNo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ParseException {
Integer id = Integer.parseInt(request.getParameter("idno"));
adrReportBiz.deleteAdrReportNo(id);
adrReportBiz.delAppriseInfoId(id);
return SearchAdrReport(mapping, form, request, response);
}
相对应页面上就是这样写的:function approveDel(){
var id = document.form1.idno.value;
        if(confirm("确定要删除吗?")) {
document.form1.action = "<%=request.getContextPath()%>/AdrReport.do?method=delReportNo&idno="+id;
this.returnValue="d"+id;
this.close();
}
   }

解决方案 »

  1.   

    没有报错,只是把AdrReport这张表的信息删除掉了,而AppriseInfo表中的信息没有被删除掉!
    我现在要实现的就是把这两张表的信息同时被删除掉就可以了!
      

  2.   


    你alert(id)在js里,看id有没有被取出来!
    用的是hibernate吗?
      

  3.   

    function approveDel(){ 
    var id = document.form1.idno.value; 
            if(confirm("确定要删除吗?")) { 
    document.form1.action = " <%=request.getContextPath()%>/AdrReport.do?method=delReportNo&idno="+id; 
    this.returnValue="d"+id; 
    this.close(); 

    }这个js好像也有点问题!!
    好像差document.form1.submit();你确定页面上有<form id='form1' name='idno'>吗?
      

  4.   

    这个项目我是用的struts+hibernate+spring,是的,确定有:
    <form name="form1" action="/AdrReport.do?method=SearchAdrReport" method="post">
    <input type="hidden" name="idno" value="${reporteeddetail.id}" />....................
    ....................
    </form>什么修改、删除的方法都写好了,我直接调用就可以了,关键是我不知道怎么去实现同时删除两张的表相关记录?根据id来删,但就不知道如何去写?
    非常的感谢!帮帮我!
      

  5.   

    AdrReport  和 AppriseInfo
    2张表的hbn.xml里的有没有配置他们的关联关系啊!
    如果有配置在看看是不是AdrReport少配了cascade="delete"级联关系!!
      

  6.   

    你是说的是不是还要在这里面配啊
     比如说:<!-- 一张报表对应多个ADR名称 -->
            <set name="report_adrname" cascade="all" inverse="true" fetch="select" lazy="false">
              <key>
            <column name="reportId"/>
              </key>
            <one-to-many class="com.adr.report.reportmanage.bean.ReportName"/>
           </set> 将它更改为:        <set name="???" cascade="all" inverse="true" fetch="delete" lazy="false">
              <key>
            <column name="reportId"/>
              </key>
            <one-to-many class="com.adr.report.reportmanage.bean.AppriseInfo"/>
           </set> 其实AppriseInfo中的bean有以下实体: private AdrReport report;
     
    public AdrReport getReport() {
    return report;
    } public void setReport(AdrReport report) {
    this.report = report;
    }比如说是不是可以再通过它report.id  什么的,来进行删除操作,是这样的吗?
      

  7.   

    是的!!<set name="???" cascade="all" inverse="true" fetch="delete" lazy="false"> 
    private AdrReport report; 
    ???一定要对应report保存一致!
      

  8.   

    还是不行,不知道action里面的方法具体该怎么写?
    需要怎么改才可以啊
      

  9.   

    使用hibernate级联删除,就行了
      

  10.   


    就是对应AdrReport表中的id,也就是reportId是AdrReport表中id的外键. 
    那就先根据主表的ID查出从表中Id相同的,删除除从表后,再要据ID删除主表.注意:
    写到同一个DAO里,交给同一个事务,这样删除出错的话会回滚.
      

  11.   

    关键是在action里面具体该怎么去写: public ActionForward delReportNo(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws ParseException {
    AdrReport report = new AdrReport();

    Integer id = Integer.parseInt(request.getParameter("idno"));
    adrReportBiz.deleteAdrReportNo(id);
    return SearchAdrReport(mapping, form, request, response);
    }这个删除的操作应该怎么去实现?该怎么改才可以?帮我看看!谢谢!