<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

    Modifying detached objects

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

    Many applications need to retrieve an object in one transaction, send it to the UI layer for manipulation, then save the changes in a new transaction. Applications that use this kind of approach in a high-concurrency environment usually use versioned data to ensure isolation for the "long" unit of work.

    Hibernate supports this model by providing for reattachment of detached instances using the Session.update() or Session.merge() methods:

    // in the first session
    Cat cat = (Cat) firstSession.load(Cat.class, catId);
    Cat potentialMate = new Cat();
    firstSession.save(potentialMate);
    // in a higher layer of the application
    cat.setMate(potentialMate);
    // later, in a new session
    secondSession.update(cat);  // update cat
    secondSession.update(mate); // update mate

    If the Cat with identifier catId had already been loaded by secondSession when the application tried to reattach it, an exception would have been thrown.

    Use update() if you are sure that the session does not contain an already persistent instance with the same identifier, and merge() if you want to merge your modifications at any time without consideration of the state of the session. In other words, update() is usually the first method you would call in a fresh session, ensuring that reattachment of your detached instances is the first operation that is executed.

    The application should individually update() detached instances reachable from the given detached instance if and only if it wants their state also updated. This can be automated of course, using transitive persistence, see Section 10.11, “Transitive persistence”.

    The lock() method also allows an application to reassociate an object with a new session. However, the detached instance has to be unmodified!

    //just reassociate:
    sess.lock(fritz, LockMode.NONE);
    //do a version check, then reassociate:
    sess.lock(izi, LockMode.READ);
    //do a version check, using SELECT ... FOR UPDATE, then reassociate:
    sess.lock(pk, LockMode.UPGRADE);

    Note that lock() can be used with various LockModes, see the API documentation and the chapter on transaction handling for more information. Reattachment is not the only usecase for lock().

    Other models for long units of work are discussed in Section 11.3, “Optimistic concurrency control”


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


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 99视频免费在线观看| 免费夜色污私人影院网站| 国产在线观看无码免费视频| 又粗又硬又黄又爽的免费视频 | 亚洲免费综合色在线视频| 亚洲AV日韩AV永久无码下载| 两个人看的www免费视频中文| 浮力影院亚洲国产第一页| 中文字幕一区二区三区免费视频| 亚洲午夜AV无码专区在线播放| 一级白嫩美女毛片免费| 亚洲精品专区在线观看| 一区二区三区在线免费观看视频| 色噜噜亚洲精品中文字幕| 成全视频免费观看在线看| 亚洲av日韩av天堂影片精品| 久久午夜羞羞影院免费观看| 亚洲国产成人资源在线软件| 久久久久国产精品免费免费搜索 | 77777_亚洲午夜久久多人| 最近2019中文字幕免费直播| 亚洲13又紧又嫩又水多| 在线精品免费视频无码的 | 国产情侣久久久久aⅴ免费| 一区二区三区亚洲| 成人激情免费视频| 黄色a三级免费看| 亚洲国产成人片在线观看无码 | 91亚洲va在线天线va天堂va国产 | 国产成人亚洲影院在线观看| 久久久久久久99精品免费观看| 亚洲综合无码一区二区三区| 香蕉高清免费永久在线视频| 国产免费一区二区三区免费视频| 亚洲国产综合专区在线电影| 毛片A级毛片免费播放| 亚欧国产一级在线免费| 亚洲精品午夜视频| 亚洲国产精品一区二区三区久久| 久久国产精品成人免费| 亚洲乱亚洲乱妇无码|