主从表关系,页面提交修改的时候从表里的many-to-one 这个字段保存过就是null,是为什么。页面里给个隐藏域把many-to-one 对象放进去,进行提交不了,该怎么解决?

解决方案 »

  1.   

    加上inverse =true ,存储的交给多的一方来处理
      

  2.   

    没用,本来想在从表对应的那个many-to-one为null的时候在查询set进去,可是当从表多条的时候对应同一个会出现a different object with the same identifier value was already associated with the session
      

  3.   

    修改之前做了查询操作?
    a different object with the same identifier value was already associated with the session
    一般都是查询了之后缓存中存在了一个对象的内存地址,而你把另外一个对象赋值给修改的对象时才会出现这样的情况。可以先通过
    List XXs = getXXList();
    XXs.removeAll();
    for(;;){
        XXs.add()
    }
    这样的话update的时候XXs的内存地址与缓存中的内存地址一致应该是可以的
      

  4.   

    目前我做的是在修改完后,在进行查询一次该主表,查询前把session先clear掉,这样就可以查出来了。