<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”


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


    網站導航:
     
    主站蜘蛛池模板: 日韩视频在线免费| 久久精品中文字幕免费| 成人毛片18女人毛片免费 | 国产美女无遮挡免费视频网站| 日本亚洲欧洲免费天堂午夜看片女人员| 亚洲国产成人久久笫一页| 无码人妻一区二区三区免费视频| 国产免费小视频在线观看| 大桥未久亚洲无av码在线| 无人在线观看免费高清| 午夜亚洲www湿好大| 欧洲精品99毛片免费高清观看| 亚洲欧洲免费视频| free哆啪啪免费永久| 久久精品国产亚洲AV久| 女人18毛片水真多免费看| 精品韩国亚洲av无码不卡区| 免费在线观看黄色毛片| 91成人免费观看在线观看| 久久精品国产亚洲AV电影| 日本免费网址大全在线观看| 亚洲精品蜜夜内射| 亚洲国产精品日韩| 最近中文字幕mv免费高清视频8| 亚洲高清视频在线| 亚洲精品无码你懂的网站| 久久久久国产精品免费看| 亚洲综合小说另类图片动图| 亚洲国产精品日韩| 黄网站色在线视频免费观看| 久久亚洲精品11p| 久久亚洲国产午夜精品理论片| 麻豆国产精品免费视频| 国产亚洲精品美女2020久久| 亚洲成AV人片在线观看无码 | 99精品视频在线视频免费观看 | 国产一区视频在线免费观看| 男女一边摸一边做爽的免费视频 | 精品在线免费观看| 久久亚洲精品国产精品婷婷| 亚洲老妈激情一区二区三区|