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

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

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

    寫程序,做產(chǎn)品,過日子

    成功其實(shí)很簡(jiǎn)單,就是強(qiáng)迫自己堅(jiān)持下去

    BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
      69 Posts :: 1 Stories :: 92 Comments :: 0 Trackbacks

    Collection mapping table

    HBM Element Java Interface Java Implementation
    <set> Set HashSet
    <set> with order SortedSet TreeSet
    <list> List ArrayList
    <bag>, <idbag> Collection ArrayList
    <map> Map HashMap
    <map> with order SortedMap TreeMap
    <array>, <primitive-array> N/A array

     

    Sample Tables

    CREATE TABLE `core_sample_company` (
      `companyId` decimal(18,0) NOT NULL,
      `companyName` varchar(128) NOT NULL,
      `description` varchar(1024) default NULL,
      PRIMARY KEY  (`companyId`)
    );

    CREATE TABLE `core_sample_role` (
      `roleId` decimal(18,0) NOT NULL,
      `roleName` varchar(128) NOT NULL,
      `companyId` decimal(18,0) NOT NULL,
      `description` varchar(1024) default NULL,
      PRIMARY KEY  (`roleId`)
    );

    CREATE TABLE `core_sample_user` (
      `userId` decimal(18,0) NOT NULL,
      `userName` varchar(128) NOT NULL,
      `companyId` decimal(18,0) NOT NULL,
      `defaultRoleId` decimal(18,0) default NULL,
      `description` varchar(1024) default NULL,
      PRIMARY KEY  (`userId`)
    );

    CREATE TABLE `core_sample_user_role` (
      `userId` decimal(18,0) NOT NULL,
      `roleId` decimal(18,0) NOT NULL,
      `pripority` int(11) NOT NULL,
      PRIMARY KEY  (`userId`,`roleId`)
    );

    HBM defintion

    The definiton of <set>, <bag>, <list> is similar.

    Defines a collection whose element type is simple data type.

    <class name="SampleCompany" table="core_sample_company">

            <bag name="roleNames" table="core_sample_role" lazy="false" >
                <key column="companyId"/>
                <element column="roleName" type="string"/>
            </bag>

    </class>

    Query HQL: select c.id, c.name, r from SampleCompany c left join c.roleNames r

    Defines a collection whose element type is another mapped java class

    <class name="SampleCompany" table="core_sample_company">   

       <bag name="roles" cascade="none">
                <key column="companyId"/>
                <one-to-many class="SampleRole" not-found="ignore"/>
            </bag>

    </class>

    Query HQL: select c.id, c.name, r.name from SampleCompany c left join c.role r

    Pay attention that key column is a foreign column of SampleRole table.

    Defines a list with list-index

    <list> is not a popular element. It request a index column in table. The index column is the index of java List, it has to be a sequence starts from 0.

    <class name="SampleUser" table="core_sample_user">

         <list name="roles" table="core_sample_user_role" cascade="all" lazy="false" >
                <key><column name="userId" sql-type="integer"/></key>
                <index column="priority"></index>
                <many-to-many class="SampleRole">
                    <column name="roleId"></column>
                </many-to-many>
            </list>

    </class>

    The benifit of <list> is it alwasy sorts list by index column. However, It is hard to resort the list. I tried remove a role from role list and add it to another poisition. When save the role list, an exception throwed:

    java.sql.BatchUpdateException: Duplicate entry 'user001-role003 for key 1

    This should be a hibernate bug.

    Defines a bag with relationship table

    <class name="SampleRole" table="core_sample_role">

          <bag name="users" table="core_sample_user_role" cascade="none" lazy="false">
                <key><column name="roleId" sql-type="integer"/></key>
                <many-to-many class="SampleUser">
                    <column name="userId"></column>
                </many-to-many>
            </bag>

    </class>

    • Key column is foreign column from relationship table to current table(SampleRole>
    • many-to-many sub column is foreign column from relationship table to target table (SampleUser)
    posted on 2007-10-24 11:09 Welkin Hu 閱讀(717) 評(píng)論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 免费在线黄色网址| 特级无码毛片免费视频尤物| 亚洲视频免费在线看| 91天堂素人精品系列全集亚洲| 久久国产乱子伦精品免费午夜| 69pao强力打造免费高清| 成人免费福利视频| 国产免费久久精品久久久| 亚洲国产精品国自产拍AV| 亚洲美女视频一区| 巨波霸乳在线永久免费视频 | 亚洲av无码专区首页| 美女被吸屁股免费网站| 拍拍拍无挡视频免费观看1000| 67194成手机免费观看| 亚洲系列中文字幕| 成人免费av一区二区三区| 日韩免费无砖专区2020狼| 亚洲成av人影院| 日韩精品极品视频在线观看免费| 免费在线观看视频a| 波霸在线精品视频免费观看| 国产亚洲无线码一区二区 | 亚洲大香伊人蕉在人依线| 一级毛片人与动免费观看| xxxxx免费视频| 亚洲女久久久噜噜噜熟女| 亚洲第一成年免费网站| 天天影院成人免费观看| 亚洲人成网亚洲欧洲无码| 午夜精品免费在线观看| va天堂va亚洲va影视中文字幕| 国产精品福利片免费看| 免费国产成人高清在线观看麻豆| 亚欧洲精品在线视频免费观看 | 日本高清高色视频免费| 亚洲国产成人精品女人久久久| 久久久久se色偷偷亚洲精品av | 久久久久久亚洲Av无码精品专口| 最近免费中文字幕MV在线视频3| 国产成人毛片亚洲精品|