各位兄弟姐妹,帮我看看这样的问题,SSH集成开发的项目,我在struts调用DAO时候,执行了两次load,因为我要加载这两个对象来更新,可是他报错了,有可能前面那次把session关闭了,下一个load方法就不可以调用了,那怎么办呢?这两个对象是ONE-TO-MANY关系。事务是用spring事务管理器配置实现的。

解决方案 »

  1.   

    使用opensessioninviewfilter或opensessioninviewinterceptor保持session打开。
      

  2.   

    public ActionForward update_writes(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    LazyValidatorForm f = (LazyValidatorForm) form;// 获得动态懒form
    String id=(String)f.get("id");
    String bt = (String) f.get("bt");
    String write_type = (String) f.get("write_type");
    String con = (String) f.get("con");
    String write_heart = (String) f.get("write_heart");
    String write_quanxian = (String) f.get("write_quanxian");
    Writetype wr=this.writestypedaoImpl.find_Writetype(new Integer(write_type));//加载一次
        Writes w=this.writesdaoImpl.find_Writes(new Integer(id));//加载2次
        w.setWrite_bt(bt);
        w.setWrite_con(con);
        w.setWritetype(wr);
        w.setWrite_date(new Date());
        w.setWrite_heart(write_heart);
        w.setWrite_quanxian(write_quanxian);
        this.writesdaoImpl.modify_Writes(w); return mapping.findForward("writes_list_add");
    }听网上说这是session管理问题,但我这里是用spring管理事务,报错如下
    org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.cw.pojo.Writes#23]Writes表是外键表,是多的一方,而Writetype是一的一的一方,当我更新一的一方时候同时更新Writetype
      

  3.   

    对,把配置文件中的lazy属性改为false试试
      

  4.   

    使用opensessioninviewfilter或opensessioninviewinterceptor保持session打开。请问这个具体怎么实现呢?