<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Neil的備忘錄

    just do it
    posts - 66, comments - 8, trackbacks - 0, articles - 0

    Automatic state detection

    Posted on 2008-11-01 10:10 Neil's NoteBook 閱讀(107) 評論(0)  編輯  收藏

    Hibernate users have requested a general purpose method that either saves a transient instance by generating a new identifier or updates/reattaches the detached instances associated with its current identifier. The saveOrUpdate() method implements this functionality.

    // in the first session
    Cat cat = (Cat) firstSession.load(Cat.class, catID);
    // in a higher tier of the application
    Cat mate = new Cat();
    cat.setMate(mate);
    // later, in a new session
    secondSession.saveOrUpdate(cat);   // update existing state (cat has a non-null id)
    secondSession.saveOrUpdate(mate);  // save the new instance (mate has a null id)

    The usage and semantics of saveOrUpdate() seems to be confusing for new users. Firstly, so long as you are not trying to use instances from one session in another new session, you should not need to use update(), saveOrUpdate(), or merge(). Some whole applications will never use either of these methods.

    Usually update() or saveOrUpdate() are used in the following scenario:

    • the application loads an object in the first session

    • the object is passed up to the UI tier

    • some modifications are made to the object

    • the object is passed back down to the business logic tier

    • the application persists these modifications by calling update() in a second session

    saveOrUpdate() does the following:

    • if the object is already persistent in this session, do nothing

    • if another object associated with the session has the same identifier, throw an exception

    • if the object has no identifier property, save() it

    • if the object's identifier has the value assigned to a newly instantiated object, save() it

    • if the object is versioned (by a <version> or <timestamp>), and the version property value is the same value assigned to a newly instantiated object, save() it

    • otherwise update() the object

    and merge() is very different:

    • if there is a persistent instance with the same identifier currently associated with the session, copy the state of the given object onto the persistent instance

    • if there is no persistent instance currently associated with the session, try to load it from the database, or create a new persistent instance

    • the persistent instance is returned

    • the given instance does not become associated with the session, it remains detached 


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 国产免费一区二区三区VR| 亚洲综合精品一二三区在线| 思思re热免费精品视频66| 一级做a爱片特黄在线观看免费看| 亚洲一区AV无码少妇电影| 亚洲Av永久无码精品三区在线| 又爽又黄无遮挡高清免费视频| 国产一卡2卡3卡4卡2021免费观看| 精品视频一区二区三区免费| 日本永久免费a∨在线视频| 亚洲欧美日韩综合久久久| 亚洲激情视频网站| 亚洲大尺度无码专区尤物| 亚洲精品97久久中文字幕无码| 国产成人免费a在线视频app| 特级做A爰片毛片免费69| 最近免费中文在线视频| 久久久免费精品re6| 成人影片一区免费观看| 一区二区三区免费精品视频| 美女18毛片免费视频| 亚洲成在人线aⅴ免费毛片| jlzzjlzz亚洲jzjzjz| 亚洲国产成人精品无码区在线秒播| 久久精品国产亚洲AV麻豆王友容 | 久久亚洲AV成人无码软件| 亚洲国产精品一区二区第一页| 亚洲午夜无码片在线观看影院猛| 免费国产成人高清视频网站| 日本无吗免费一二区| 免费永久国产在线视频| 四虎在线播放免费永久视频 | 99热亚洲色精品国产88| 亚洲午夜精品国产电影在线观看| 亚洲视频在线视频| 亚洲视频在线观看免费| 亚洲av成人综合网| 亚洲中文字幕无码久久| 亚洲AV成人精品一区二区三区| 小说专区亚洲春色校园| 深夜福利在线视频免费|