<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”


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


    網站導航:
     
    主站蜘蛛池模板: 国产一级片免费看| 亚洲av无码成h人动漫无遮挡| 中文无码亚洲精品字幕| 日韩亚洲国产高清免费视频| 91精品国产免费久久国语蜜臀 | 18女人腿打开无遮掩免费| 成人浮力影院免费看| 又色又污又黄无遮挡的免费视| 国产一级淫片免费播放| 亚洲AV无码一区二区三区系列| 在线观看免费视频一区| 成人午夜视频免费| 精品久久久久久亚洲| 亚洲桃色AV无码| 国产精品久久免费| 亚洲日本久久久午夜精品| 最近最好最新2019中文字幕免费| 亚洲福利在线视频| 极品色天使在线婷婷天堂亚洲 | 午夜在线a亚洲v天堂网2019| 噼里啪啦电影在线观看免费高清| 亚洲一区二区三区在线观看精品中文| 久久最新免费视频| 免费不卡中文字幕在线| 一级毛片视频免费观看| 在线观看91精品国产不卡免费| 亚洲精品影院久久久久久| 黄色网页在线免费观看| 久久久综合亚洲色一区二区三区| 国产成人免费高清激情明星| 亚洲成av人在线视| 69堂人成无码免费视频果冻传媒 | 亚洲AV无码成人专区| 国产偷伦视频免费观看| 亚洲伊人久久精品| 国产电影午夜成年免费视频| 亚洲AV永久无码天堂影院 | av电影在线免费看| 亚洲精品综合久久| 男人免费视频一区二区在线观看| 国产最新凸凹视频免费|