<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 


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


    網站導航:
     
    主站蜘蛛池模板: 亚洲精品和日本精品| 在线免费观看中文字幕| 国产成人亚洲精品狼色在线| 亚洲成AV人片高潮喷水| 性感美女视频免费网站午夜| 亚洲人成免费网站| 噼里啪啦电影在线观看免费高清 | 亚洲国产精品无码久久久秋霞2| 无码日韩人妻AV一区免费l | 最近免费中文字幕视频高清在线看| 亚洲最新黄色网址| 黄页网站免费观看| 一本天堂ⅴ无码亚洲道久久| 天天拍拍天天爽免费视频| 久久久久久亚洲精品无码| 亚洲国产精品毛片av不卡在线| 香蕉视频免费在线| 亚洲色成人中文字幕网站 | 手机看片国产免费永久| 亚洲色成人网站WWW永久| 午夜视频在线免费观看| 亚洲明星合成图综合区在线| 成人毛片18女人毛片免费视频未| 亚洲AV永久无码精品一福利| 亚洲高清国产拍精品青青草原 | 国产亚洲一区二区三区在线不卡| 特级做A爰片毛片免费看无码| 亚洲欧洲日韩不卡| 国产福利在线免费| 青青青视频免费观看| 亚洲国产精彩中文乱码AV| 最近中文字幕高清免费中文字幕mv| 亚洲伦理中文字幕| 亚洲国产人成中文幕一级二级| 久草福利资源网站免费| 精品日韩99亚洲的在线发布| 免费一区二区三区四区五区| 国产一区二区三区免费| 亚洲AV日韩综合一区尤物| 亚洲精品专区在线观看| 99国产精品免费视频观看|