<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jinfeng_wang

    G-G-S,D-D-U!

    BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
      400 Posts :: 0 Stories :: 296 Comments :: 0 Trackbacks

     

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"
    >

    <hibernate-mapping>
      
    <class name="com.oreilly.hh.Album" table="ALBUM">
        
    <meta attribute="class-description">
          Represents an album in the music database, an organized list of tracks.
          @author Jim Elliott (with help from Hibernate)
        
    </meta>

        
    <id name="id" type="int" column="ALBUM_ID">
          
    <meta attribute="scope-set">protected</meta>
          
    <generator class="native"/>
        
    </id>

        
    <property name="title" type="string">
          
    <meta attribute="use-in-tostring">true</meta>
          
    <column name="TITLE" not-null="true" index="ALBUM_TITLE"/>
        
    </property>

        
    <property name="numDiscs" type="integer" not-null="true"/>

        
    <set name="artists" table="ALBUM_ARTISTS">
          
    <key column="ALBUM_ID"/>
          
    <many-to-many class="com.oreilly.hh.Artist" column="ARTIST_ID"/>
        
    </set>

        
    <set name="comments" table="ALBUM_COMMENTS">
          
    <key column="ALBUM_ID"/>
          
    <element column="COMMENT" type="string"/>
        
    </set>

        
    <list name="tracks" table="ALBUM_TRACKS" cascade="all">
          
    <meta attribute="use-in-tostring">true</meta>
          
    <key column="ALBUM_ID"/>
          
    <index column="POS"/>
          
    <composite-element class="com.oreilly.hh.AlbumTrack">
            
    <many-to-one name="track" class="com.oreilly.hh.Track" cascade="all">
              
    <meta attribute="use-in-tostring">true</meta>
              
    <column name="TRACK_ID"/>
            
    </many-to-one>
            
    <property name="disc" type="integer" not-null="true"/>
            
    <property name="positionOnDisc" type="integer" not-null="true"/>
          
    </composite-element>
        
    </list>

        
    <property name="added" type="date">
          
    <meta attribute="field-description">When the album was created</meta>
        
    </property>

      
    </class>
    </hibernate-mapping>


     

    The cascade attribute tells Hibernate that you want operations performed on a 'parent' object to be transitively applied to its 'child' or 'dependent' objects. It's applicable to all forms of collections and associations. There are several possible values to choose among. The most common are none (the default), save-update, delete, and all (which combines save-update and delete). You can also change the default from none to save-update throughout your entire mapping document by supplying a default-cascade attribute in the hibernate-mapping tag itself.

    級聯(lián)(cascade)屬性告訴hibernate:所有對父對象的操作都將付諸于子對象和依賴對象上。級聯(lián)可以應(yīng)用于各種形式的集合和關(guān)聯(lián)中。這里級聯(lián)的具體取值可以有多個,最常用的有:none(默認(rèn)值),save-update,delete和all(其中包含了save-update和delete)。你可以在hibernate-mappiong tag中通過設(shè)置default-casade屬性,修改這里的casade的默認(rèn)值,例如修改其默認(rèn)值為save-update。

    In our example, we want the tracks owned by an album to be automatically managed by the album, so that when we delete the album, its tracks are deleted. Note that we need to apply the
    cascade attribute both to the tracks collection and its constituent track element to achieve this. Also, by using a cascade value of all, we eliminate the need to explicitly save any Track objects we create for the album—the addAlbumTrack() method of Example 5-7 no longer needs the line:

       session.save(track);

    在我們的例子中,我們希望track完全由album自動掌管,當(dāng)我們刪除album時,它的track也會被刪除。注意,這里我們需要在兩處設(shè)置casade屬性實現(xiàn)此任務(wù):tracks集合和它的組成元素track。同樣,由于我們講casade設(shè)置為all,那么不再需要顯式的保存為album創(chuàng)建的track對象,5-7例子中的addAlbumTrack方法不再需要調(diào)用session.save(track)方法。

    By telling Hibernate that it's fully responsible for the relationship between an album and its track, we enable it to persist tracks when they're added to the album as well as delete them when the album itself is deleted.


    通過高知hibernate,由其完全負(fù)責(zé)album和track直接的關(guān)系,可以保證track在加入到album時自動保存,在album刪除時自動刪除。

    Delegating this sort of bookkeeping to the mapping layer can be very convenient, freeing you to focus on more abstract and important tasks, so it is worth using when appropriate. It's reminiscent of the liberation provided by Java's pervasive garbage collection, but it can't be as comprehensive because there is no definitive way to know when you're finished with persistent data by performing reachability analysis; you need to indicate it by calling
    delete() and establishing lifecycle connections. The trade-off between flexibility and simple automation is yours to make, based on the nature of your data and the needs of your project.
    將這樣的任務(wù)完全交代給持久層使得我們的任務(wù)更加的簡便,可以讓我們將注意力投注于更抽象更重要的業(yè)務(wù),因此恰當(dāng)?shù)氖褂胏asade是值得的,這就像java的垃圾收集一樣,使我們的工作得到了一定的解放。但是,由于目前并沒有任何的可達(dá)性分析方法,可以確切的知道“你是否已經(jīng)不再需要此持久層數(shù)據(jù)”,因此你必須調(diào)用delete()方法,才能建立起此生命周期鏈接。你必須依據(jù)你的數(shù)據(jù)的特點(diǎn)和項目的需要,在靈活性和自動化的簡單性進(jìn)行權(quán)衡。

    For example, if you use Collections methods to remove a Track from an Album's tracks property, this breaks the link between the Album and Track but does not actually delete the Track record. Even if you later delete the entire Album, this Track will remain, because it wasn't linked to the Album at the time that it was deleted.
    例如:如果你使用Album的tracks collection的remove方法,刪除一個track,這將會移除album和track直接的鏈接,但是它并沒真正的刪除track記錄。即使你后來整個的刪除album,這個track也將會繼續(xù)保留著,因為此時該track已經(jīng)和album失去了鏈接。
    //( 譯者注)這里的含義是:級聯(lián)是有范圍的,表ALBUM和表TRACK之間通過表Album_Tracks建立了聯(lián)系。在albu.hbm.xml中,進(jìn)行了級聯(lián)配置,使得Album和ALBUM_TRACKS之間級聯(lián)。當(dāng)刪除某個album時,那么相應(yīng)的ALBUM_TRACKS中的記錄也將刪除。如果對album中的tracks執(zhí)行remove方法時,那么ALBUM_TRACKS中的相應(yīng)記錄也將刪除。但是這里的級聯(lián)卻無法延伸到表TRACK中,TRACK表中的記錄將安然無恙,依然存在。
    //原文中的tracks出現(xiàn)在兩處,一個是Album對象的屬性,其對應(yīng)著ALBUM_TRACKS的記錄。一個則是單獨(dú)的TRACK表,所以表述十分容易引起混淆。
    posted on 2005-04-03 21:43 jinfeng_wang 閱讀(1060) 評論(0)  編輯  收藏 所屬分類: hibernate
    主站蜘蛛池模板: 亚洲热妇无码AV在线播放| 亚洲精品人成网线在线播放va| 国产乱子精品免费视观看片| 亚洲人成色77777在线观看| 亚洲欧洲中文日韩久久AV乱码| 日美韩电影免费看| 亚洲阿v天堂在线2017免费| 亚洲一区二区三区日本久久九| 色www永久免费视频| 亚洲成年人电影网站| 又粗又大又猛又爽免费视频| 特级精品毛片免费观看| 久久久久亚洲精品无码网址色欲| 国产亚洲人成网站观看| 天天看片天天爽_免费播放| 在线观看黄片免费入口不卡| 亚洲日韩精品国产3区| 亚洲AV无码乱码国产麻豆穿越 | 色播亚洲视频在线观看| 免费一级e一片在线播放| 亚洲国产精品免费在线观看| 一级毛片免费播放男男| 亚洲三级高清免费| 亚洲天堂中文字幕| 国产亚洲精品高清在线| 日本媚薬痉挛在线观看免费| 最近免费中文字幕大全免费版视频| 日本黄页网址在线看免费不卡| 中中文字幕亚洲无线码| 亚洲AV人人澡人人爽人人夜夜| 免费一级e一片在线播放| 最近中文字幕免费mv视频8| 美女内射无套日韩免费播放| 一二三区免费视频| 偷自拍亚洲视频在线观看| 亚洲18在线天美| 亚洲高清资源在线观看| 毛片免费观看的视频| 日韩av无码久久精品免费| 成人无码区免费A∨直播| 青娱乐在线免费观看视频|