<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
    主站蜘蛛池模板: 日韩亚洲国产二区| 免费观看男人免费桶女人视频| 免费A级毛片无码A| 国产精品亚洲专区无码牛牛| 成人免费一级毛片在线播放视频| 亚洲综合在线成人一区| 最近2019免费中文字幕6| 亚洲高清中文字幕综合网| 91香蕉国产线在线观看免费| 久久精品国产亚洲AV电影| 四虎国产精品永久免费网址 | 亚洲av无码偷拍在线观看| 在线观看免费污视频| 亚洲精品无码mⅴ在线观看| 国内大片在线免费看| 羞羞漫画页面免费入口欢迎你| 亚洲国产成人久久综合一区77| 男女猛烈无遮掩视频免费软件| 亚洲精品黄色视频在线观看免费资源| 农村寡妇一级毛片免费看视频| www.亚洲日本| 成人免费毛片内射美女APP| 亚洲国产成人久久综合| 亚洲精品亚洲人成在线观看下载| 成人午夜免费视频| 亚洲av无码国产精品夜色午夜| 16女性下面无遮挡免费| 亚洲日韩精品无码专区| 亚洲精品色婷婷在线影院| 久久精品一区二区免费看| 亚洲人成伊人成综合网久久| 国产福利免费在线观看| 午夜无遮挡羞羞漫画免费| 美女免费视频一区二区| 亚洲国产精品va在线播放| 一二三四影视在线看片免费 | 久久久久无码专区亚洲av| 99xxoo视频在线永久免费观看| www.亚洲成在线| 在线精品亚洲一区二区小说| 亚洲免费视频网址|