<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

    Loading an object

    Posted on 2008-11-01 10:07 Neil's NoteBook 閱讀(124) 評論(0)  編輯  收藏

    The load() methods of Session gives you a way to retrieve a persistent instance if you already know its identifier. load() takes a class object and will load the state into a newly instantiated instance of that class, in persistent state.

    Cat fritz = (Cat) sess.load(Cat.class, generatedId);
    // you need to wrap primitive identifiers
    long id = 1234;
    DomesticCat pk = (DomesticCat) sess.load( DomesticCat.class, new Long(id) );

    Alternatively, you can load state into a given instance:

    Cat cat = new DomesticCat();
    // load pk's state into cat
    sess.load( cat, new Long(pkId) );
    Set kittens = cat.getKittens();

    Note that load() will throw an unrecoverable exception if there is no matching database row. If the class is mapped with a proxy, load() just returns an uninitialized proxy and does not actually hit the database until you invoke a method of the proxy. This behaviour is very useful if you wish to create an association to an object without actually loading it from the database. It also allows multiple instances to be loaded as a batch if batch-size is defined for the class mapping.

    If you are not certain that a matching row exists, you should use the get() method, which hits the database immediately and returns null if there is no matching row.

    Cat cat = (Cat) sess.get(Cat.class, id);
    if (cat==null) {
    cat = new Cat();
    sess.save(cat, id);
    }
    return cat;

    You may even load an object using an SQL SELECT ... FOR UPDATE, using a LockMode. See the API documentation for more information.

    Cat cat = (Cat) sess.get(Cat.class, id, LockMode.UPGRADE);

    Note that any associated instances or contained collections are not selected FOR UPDATE, unless you decide to specify lock or all as a cascade style for the association.

    It is possible to re-load an object and all its collections at any time, using the refresh() method. This is useful when database triggers are used to initialize some of the properties of the object.

    sess.save(cat);
    sess.flush(); //force the SQL INSERT
    sess.refresh(cat); //re-read the state (after the trigger executes)

    An important question usually appears at this point: How much does Hibernate load from the database and how many SQL SELECTs will it use? This depends on the fetching strategy and is explained in Section 19.1, “Fetching strategies”


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


    網站導航:
     
    主站蜘蛛池模板: 一个人看的www在线免费视频 | 在线亚洲午夜理论AV大片| 18禁亚洲深夜福利人口| 韩国欧洲一级毛片免费 | 亚洲av片一区二区三区| 日韩国产欧美亚洲v片| 中文字幕视频免费在线观看| 亚洲一级黄色视频| 久久久久免费视频| 亚洲av日韩av天堂影片精品| a级成人毛片免费视频高清| 国产成A人亚洲精V品无码性色| 国产做国产爱免费视频| 亚洲AV无码国产在丝袜线观看| 无码人妻一区二区三区免费看 | 免费**毛片在线播放直播| 深夜a级毛片免费无码| 国产成人精品久久亚洲| 西西人体免费视频| 亚洲视频一区调教| 毛片免费观看视频| 亚洲a在线视频视频| 国产成人精品免费视| 国产美女亚洲精品久久久综合| 两个人www免费高清视频| 亚洲网站视频在线观看| 黄色大片免费网站| 亚洲精品国产精品乱码视色| 国产精品久久亚洲一区二区| 中文字幕不卡亚洲 | 一级A毛片免费观看久久精品| 成人黄页网站免费观看大全| 国产精品手机在线亚洲| 亚洲不卡av不卡一区二区| 免费精品国产自产拍在线观看图片 | 国产一区二区三区亚洲综合| 久久91亚洲人成电影网站| 无码人妻一区二区三区免费手机 | 91免费资源网站入口| 黄床大片免费30分钟国产精品 | 国产高清免费视频|