为了生态平衡,请保护蛤蟆赞这一句应该是hbm.xml里面设置好级联更新选项,还要用saveOrUpdate方法吧,具体不详啊,hibernate不熟,帮你顶

解决方案 »

  1.   

    Product product=new Product();
    Product.setSn("0001");
    product.setType("类型");
    product.setColor("绿色");
    product.setInputUser("admin");
    ComponentModel cm=new ComponentModel();
    Material m=new Material();
    cm.setName("鞋帮");cm.getMaterials().add(m);
    product.getComponents().add(cm);这样试试
      

  2.   

    我已经进行控制反转了,必须被控方来更新主控方,这两句少不了
    cm.setProduct(product); 
    m.setComponentModel(cm);
      

  3.   

    所有多对一,一对多cascade都设成save,update,然后把inverse交给主表
      

  4.   

    赞成楼上的答案,另外也可以都设成all,即cascade都设成all.
      

  5.   

    inverse交给主表??单向一对多关系??这样的一次数据插入就需要两条SQL语句(insert,update),性能上应该有较大一向.而且有约束违例的问题.
    恐怕暂时只能用我现在的方法了,先插入product和component,再load出component插入material
    谢谢各位参与