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

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

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

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

    成功其實很簡單,就是強迫自己堅持下去

    BlogJava 首頁 新隨筆 聯(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 閱讀(716) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲人成电影网站免费| 亚洲精品理论电影在线观看| 久久精品国产免费观看三人同眠| 亚洲国产成人久久| 日本人护士免费xxxx视频| 日本一区二区三区在线视频观看免费| 在线观看亚洲av每日更新| 国产又大又粗又长免费视频 | 在线看片无码永久免费aⅴ| 最近2019中文免费字幕| 免费人成在线观看视频高潮| 亚洲成a人不卡在线观看| 亚洲国产精品日韩| 亚洲精品视频在线免费| 成人a毛片免费视频观看| 亚洲AV无码成人专区| 国产成人A人亚洲精品无码| 最近中文字幕无免费视频| 免费人成视频在线| 免费毛片在线看不用播放器| 野花香高清在线观看视频播放免费 | 久久免费视频网站| 午夜不卡久久精品无码免费 | 亚洲免费视频播放| 亚洲人成电影网站免费| 美女被爆羞羞网站免费| 亚洲一区二区三区不卡在线播放| 亚洲制服在线观看| 亚洲精品国产精品| 乱人伦中文视频在线观看免费| 亚洲自偷自拍另类12p| 亚洲免费日韩无码系列| 国产成人免费爽爽爽视频| 日本免费电影一区| 国产亚洲成人在线播放va| 免费一级毛片在线播放不收费| 免费看污成人午夜网站| 99精品热线在线观看免费视频| 在线毛片片免费观看| 免费观看美女用震蛋喷水的视频 | 91成人在线免费观看|