merge只是简单的把对像关联到session中事务提交后更改数据库,update会直接更改数据库吧

解决方案 »

  1.   

    update只作更新操作。
    merge:根据所给对象的id值来判断是更新还新增。
      

  2.   

    哦,说错了。
    看看doc得api,
    Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy of and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped with cascade="merge".
    ,根据对象得id判断,如果是没有保存状态,就做新增;否则,就从数据库装载该对象。