<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 閱讀(105) 評(píng)論(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 


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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 曰韩亚洲av人人夜夜澡人人爽| 亚洲国产AV无码专区亚洲AV| 亚洲黄网在线观看| 一级特级aaaa毛片免费观看| 亚洲福利视频一区二区| 免费看内射乌克兰女| 国产AV无码专区亚洲AWWW| 福利免费在线观看| 亚洲理论电影在线观看| 久久久久免费精品国产小说| 亚洲久本草在线中文字幕| 日本免费xxxx| 亚洲美国产亚洲AV| 在线观看国产情趣免费视频| 美女啪啪网站又黄又免费| 国产亚洲精品激情都市| 免费看男人j放进女人j免费看| 一个人免费观看www视频在线| 免费国产一级特黄久久| 国产黄色免费观看| 亚洲一区二区三区自拍公司| 日本免费大黄在线观看| 在线观看亚洲AV每日更新无码| 国产成年无码久久久免费| 亚洲黄色免费观看| 四虎影视大全免费入口| jizz免费观看视频| 亚洲第一页在线视频| 国产精品成人无码免费| 午夜在线免费视频 | 中国在线观看免费的www| 亚洲AV无码码潮喷在线观看| 免费精品国产自产拍在| 四虎精品成人免费视频| 97se亚洲综合在线| 免费鲁丝片一级观看| 免费毛片a线观看| 亚洲一本一道一区二区三区| 亚洲乱色熟女一区二区三区丝袜| 污网站在线观看免费| 91亚洲导航深夜福利|