<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 閱讀(711) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 欧美男同gv免费网站观看| 亚洲一级黄色视频| 久久亚洲精品成人| 人妻在线日韩免费视频| 自拍偷自拍亚洲精品情侣| 亚洲第一精品电影网| 一个人免费日韩不卡视频| 亚洲码一区二区三区| 丁香花免费完整高清观看| 亚洲人成网站在线观看播放| 亚洲中文字幕乱码AV波多JI| 特级做A爰片毛片免费69 | 亚洲欧洲一区二区| 99视频在线免费看| 免费人成视网站在线观看不卡 | 亚洲av无码一区二区三区观看| aⅴ在线免费观看| 中文字幕不卡亚洲| 国产成人AV片无码免费| 亚洲女人初试黑人巨高清| 国产香蕉九九久久精品免费| 美女免费精品高清毛片在线视| 久久久久国产成人精品亚洲午夜| 国产成人精品日本亚洲专| 日本免费在线观看| 久久精品国产亚洲AV蜜臀色欲| 全部免费毛片免费播放| 91在线视频免费观看| 四虎永久在线精品免费观看地址| 亚洲videos| 亚洲第一页综合图片自拍| 久久99精品视免费看| 中文字幕精品三区无码亚洲| 免费很黄很色裸乳在线观看| 精品一卡2卡三卡4卡免费视频 | 香蕉视频免费在线播放| 国产∨亚洲V天堂无码久久久| 一本一道dvd在线观看免费视频| 亚洲毛片网址在线观看中文字幕 | 亚洲中文无码卡通动漫野外| 国产午夜亚洲精品午夜鲁丝片|