<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

    Making objects persistent

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

    Newly instantiated instances of a a persistent class are considered transient by Hibernate. We can make a transient instance persistent by associating it with a session:

    DomesticCat fritz = new DomesticCat();
    fritz.setColor(Color.GINGER);
    fritz.setSex('M');
    fritz.setName("Fritz");
    Long generatedId = (Long) sess.save(fritz);

    If Cat has a generated identifier, the identifier is generated and assigned to the cat when save() is called. If Cat has an assigned identifier, or a composite key, the identifier should be assigned to the cat instance before calling save(). You may also use persist() instead of save(), with the semantics defined in the EJB3 early draft.

    • persist() makes a transient instance persistent. However, it doesn't guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at flush time. persist() also guarantees that it will not execute an INSERT statement if it is called outside of transaction boundaries. This is useful in long-running conversations with an extended Session/persistence context.

    • save() does guarantee to return an identifier. If an INSERT has to be executed to get the identifier ( e.g. "identity" generator, not "sequence"), this INSERT happens immediately, no matter if you are inside or outside of a transaction. This is problematic in a long-running conversation with an extended Session/persistence context.

    Alternatively, you may assign the identifier using an overloaded version of save().

    DomesticCat pk = new DomesticCat();
    pk.setColor(Color.TABBY);
    pk.setSex('F');
    pk.setName("PK");
    pk.setKittens( new HashSet() );
    pk.addKitten(fritz);
    sess.save( pk, new Long(1234) );

    If the object you make persistent has associated objects (e.g. the kittens collection in the previous example), these objects may be made persistent in any order you like unless you have a NOT NULL constraint upon a foreign key column. There is never a risk of violating foreign key constraints. However, you might violate a NOT NULL constraint if you save() the objects in the wrong order.

    Usually you don't bother with this detail, as you'll very likely use Hibernate's transitive persistence feature to save the associated objects automatically. Then, even NOT NULL constraint violations don't occur - Hibernate will take care of everything. Transitive persistence is discussed later in this chapter. 


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


    網站導航:
     
    主站蜘蛛池模板: 两性刺激生活片免费视频| a级黄色毛片免费播放视频| 免费观看成人毛片a片2008| 亚洲成年轻人电影网站www| 一级毛片**不卡免费播| 亚洲国产国产综合一区首页| 日韩免费在线视频| 亚洲第一页在线播放| 手机在线看永久av片免费| 亚洲熟女综合色一区二区三区| 成人午夜视频免费| 免费人妻精品一区二区三区| 亚洲区小说区图片区| 成人无码a级毛片免费| 亚洲精品国产情侣av在线| 日韩在线免费视频| 亚洲av无码片vr一区二区三区| 午夜亚洲国产成人不卡在线| 国产男女爽爽爽免费视频| 久久久亚洲欧洲日产国码农村| 国产精品成人免费福利| 亚洲jizzjizz少妇| 伊伊人成亚洲综合人网7777| 在线观看的免费网站无遮挡| 亚洲国产精品无码久久九九大片| 亚洲精品WWW久久久久久| 国产免费一区二区视频| 亚洲日韩国产精品乱-久| 亚洲精品综合久久| 99久在线国内在线播放免费观看| 亚洲欧美中文日韩视频| 亚洲中文字幕无码久久综合网| 99久久久国产精品免费牛牛| 亚洲AV无码专区国产乱码不卡 | 久久久免费精品re6| 国产成+人+综合+亚洲专| 亚洲日本va午夜中文字幕久久| **毛片免费观看久久精品| 国产天堂亚洲国产碰碰| 亚洲人成网站在线播放影院在线| 午夜免费福利在线观看|