<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 


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


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 亚洲国产一区二区a毛片| 久久精品私人影院免费看| AV在线亚洲男人的天堂| 小小影视日本动漫观看免费| 一个人看的www视频免费在线观看| 亚洲国产乱码最新视频| 亚洲欧洲第一a在线观看| 亚洲精品国产成人中文| 亚洲国产成人一区二区三区| 亚洲国产精品综合久久网络| 国产成人涩涩涩视频在线观看免费 | 一级毛片不卡免费看老司机| 国产成人精品免费久久久久| 国内自产拍自a免费毛片| 毛片视频免费观看| 在线视频免费观看爽爽爽| 全免费a级毛片免费看| 特级做A爰片毛片免费69| 亚洲免费综合色在线视频| 免费日本黄色网址| 成人亚洲综合天堂| 成人亚洲网站www在线观看| 久久亚洲精品成人无码网站| 最新国产精品亚洲| a级毛片无码免费真人久久| 最近免费字幕中文大全视频| 最近中文字幕大全免费视频| 亚洲国产成人爱av在线播放| 亚洲av无码电影网| 老司机午夜在线视频免费观| 一级成人a做片免费| 猫咪社区免费资源在线观看| 中文字幕亚洲综合久久2| av网站免费线看| 免费专区丝袜脚调教视频| 日韩精品视频免费在线观看| 91嫩草私人成人亚洲影院| 国产精品无码永久免费888| 国产成人免费a在线资源| 亚洲国产视频一区| 成年网站免费入口在线观看|