<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 閱讀(82) 評論(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毛片a级毛片免费| 国产国产人免费人成免费视频| 又爽又黄无遮挡高清免费视频 | 亚洲网址在线观看你懂的| 免费人成在线观看视频高潮| 动漫黄网站免费永久在线观看| 亚洲男人第一无码aⅴ网站| 亚洲国产成人超福利久久精品| 亚洲黄色免费观看| 亚洲制服丝袜精品久久| 免费可以看黄的视频s色| 亚洲性无码一区二区三区| 国产精品视频免费一区二区三区| 国产成人亚洲综合a∨| 亚洲午夜无码片在线观看影院猛| 国产成人无码精品久久久免费| 在线播放免费播放av片| 国产成人不卡亚洲精品91| 综合亚洲伊人午夜网| 偷自拍亚洲视频在线观看99| 亚洲国产精品一区二区三区久久| 国产日韩AV免费无码一区二区三区| 亚洲第一AV网站| 国产在线观看片a免费观看| 国产亚洲午夜精品| 国产亚洲综合成人91精品 | 亚洲色少妇熟女11p| 日本不卡免费新一二三区| 亚洲国产成人久久77| 免费高清在线影片一区| 国产激情久久久久影院老熟女免费| 亚洲AV无码一区二区二三区软件| 麻豆视频免费观看| 亚洲精品在线免费观看视频| 国产麻豆一精品一AV一免费 | 国产在线播放免费| 久草视频在线免费看| 亚洲日韩精品无码AV海量|