<set name="boabiaoinfo" cascade="all" lazy="false" inverse="true" order-by="weizhi asc">
<key column="bid" not-null="false"></key>
<one-to-many class="com.lhkj.data.po.Customerbaobiaoinfo" />
</set>
更新主表时set集合的数据不是更新的,而是添加了新数据

解决方案 »

  1.   

    cascade="all" 配置了
    删除时可以级联删除,但是更新时,原来从表内的数据没有删除,而是新加了记录
      

  2.   

     <many-to-one name="customerbaobiao" 
            column="bid" 
            unique="true"
            not-null="false" lazy="false"/>
    是啊
    那该什么弄啊
    请指教一下!
    谢谢
      

  3.   


    你想要什么效果啊?cascade不是非要设置成all的
      

  4.   

    我要的效果是更新customerbaobiao表时同时更新<set>集合的数据,就是boabiaoinfo的数据,同时可以级联删除,现在不能级联更新:
    是不是配置文件哪里有问题啊
      

  5.   

    inverse="false"
    or
    <many-to-one
    update="true"
    ......
    />
      

  6.   


      Customerbaobiao.hbm.xml
    <set name="boabiaoinfo" cascade="all" lazy="false" inverse="false" order-by="weizhi asc">
    <key column="bid" not-null="false"></key>
    <one-to-many class="com.lhkj.data.po.Customerbaobiaoinfo" />
    </set>Customerbaobiaoinfo.hbm.xml
    <many-to-one name="customerbaobiao" 
            column="bid" 
            unique="true"
            not-null="false" />看看这两个配置文件有什么不妥的
      

  7.   

        
    后台得到对象并更新对象的代码
    Customerbaobiao baobiao = new Customerbaobiao();
        
        if(baobiaoid!=null&&!baobiaoid.equals(""))
        {
         baobiao=this.myservice.findById(Customerbaobiao.class, Integer.parseInt(baobiaoid));
        
        }
        baobiao.setBaobiaoname(title);
        baobiao.setType(type);
        Set<Customerbaobiaoinfo> baobiaoinfoset = baobiao.getBoabiaoinfo();
        for(String s : baobiaoinfos)
        {
           String [] bao = s.split("-");
           Customerbaobiaoinfo bf = new Customerbaobiaoinfo();
           try{
           bf.setTablename(bao[0]);
           bf.setColumntype(Integer.valueOf(bao[1]));
           bf.setDatatype(Integer.valueOf(bao[2]));
           bf.setColumnstr(bao[3]);
           bf.setDisplayname(bao[4]);
           bf.setWeizhi(Integer.valueOf(bao[5]));
           }catch(Exception e)
           {
           e.printStackTrace();
           }
           //建立两表的关系
           bf.setCustomerbaobiao(baobiao);
           baobiaoinfoset.add(bf);
        }
        baobiao.setBoabiaoinfo(baobiaoinfoset);
      

  8.   

    Customerbaobiao baobiao = new Customerbaobiao(); 
        
        if(baobiaoid!=null&&!baobiaoid.equals("")) 
        { 
        baobiao=this.myservice.findById(Customerbaobiao.class, Integer.parseInt(baobiaoid)); 
        
        } 
        baobiao.setBaobiaoname(title); 
        baobiao.setType(type);    //断开关系 注:关系由多方维护 如一方维护还简单点
        Set<Customerbaobaobiaoinfo> infos = baobiao.get***() //具体用你定义获得Customerbaobiaoinfo对象集合的方法
        for(Customerbaobiaoinfo info : infos){
          info.setCustomerbaobiao(null);
        }    //下面代码不变 
        Set <Customerbaobiaoinfo> baobiaoinfoset = baobiao.getBoabiaoinfo(); 
        for(String s : baobiaoinfos) 
        { 
          String [] bao = s.split("-"); 
          Customerbaobiaoinfo bf = new Customerbaobiaoinfo(); 
          try{ 
          bf.setTablename(bao[0]); 
          bf.setColumntype(Integer.valueOf(bao[1])); 
          bf.setDatatype(Integer.valueOf(bao[2])); 
          bf.setColumnstr(bao[3]); 
          bf.setDisplayname(bao[4]); 
          bf.setWeizhi(Integer.valueOf(bao[5])); 
          }catch(Exception e) 
          { 
          e.printStackTrace(); 
          } 
          //建立两表的关系 
          bf.setCustomerbaobiao(baobiao); 
          baobiaoinfoset.add(bf); 
        } 
        baobiao.setBoabiaoinfo(baobiaoinfoset);
       如搞不定,发邮件:yanjun◎linktrust.com.cn