CTB

           

          2012年6月27日

          一對一關系配置

          <hibernate-mapping package="com.wepull.hibernate.pojo">
           <class name="Card" table="tbl_card">
            <id name="cardId" column="pk_card_id">
             <generator class="native"/>
            </id>
            
            <property name="cardNo" column="card_no"/>
            
            <!-- 需要維護關系的屬性,就不是普通屬性 -->
            <!-- Person和Card溝通的橋梁是外鍵fk_card_id -->
            <one-to-one name="person" property-ref="card"/>
            
            <!-- property-ref="card":通過Person的外鍵pk_card_id,可以得到pk_person_id -->
           </class>
          </hibernate-mapping>



          <hibernate-mapping package="com.wepull.hibernate.pojo">
           <class name="Person" table="tbl_person">
            <id name="personId" column="pk_person_id">
             <generator class="native"/>
            </id>
            
            <property name="personName" column="person_name"/>
            
            <!-- 唯一外鍵約束 -->
            <!-- 此一對一屬于多對一的特例 -->
            <!-- 先假設多個人共用一張卡,再給fk_card_id添加唯一約束,就變成了一對一關系 -->
            <many-to-one name="card" column="fk_card_id" unique="true" cascade="all"/>
           </class>
          </hibernate-mapping>

          posted @ 2012-06-27 15:55 千面獨行客 閱讀(153) | 評論 (1)編輯 收藏

          一對多關系配置

          <hibernate-mapping package="com.wepull.hibernate.pojo">
           <class name="Clazz" table="tbl_class">
            <id name="classId" column="pk_class_id">
             <generator class="native"/>
            </id>
            
            <property name="className" column="class_name"/>
            
            <!-- inverse="false":不放棄維護關系的權利,由Clazz維護關系 -->
            <!-- inverse="true":放棄維護關系的權利,由Student維護關系 -->
            <set name="students" inverse="true" cascade="all">
             <!-- 一的一方為多的一方指定外鍵 -->
             <key column="fk_class_id"/>
             <!-- 讓Clazz認識認識students是什么 -->
             <one-to-many class="Student"/>
            </set>
           </class>
          </hibernate-mapping>



          <hibernate-mapping package="com.wepull.hibernate.pojo">
           <class name="Student" table="tbl_student">
            <id name="studentId" column="pk_student_id">
             <generator class="native"/>
            </id>
            
            <property name="studentName" column="student_name"/>
            
            <many-to-one name="clazz" column="fk_class_id" cascade="all"/>
           </class>
          </hibernate-mapping>

          posted @ 2012-06-27 15:54 千面獨行客 閱讀(123) | 評論 (0)編輯 收藏

          多對多關系配置

          <hibernate-mapping package="com.wepull.hibernate.pojo">
           <class name="Role" table="tbl_role">
            <id name="roleId" column="pk_role_id">
             <generator class="native"/>
            </id>
            
            <property name="roleName" column="role_name"/>
            
            <!-- 對于多對多的關系,需要一張中間表 -->
            <set name="users" table="tbl_user_role">
             <!-- 中間表,通過什么字段,跟Role表產生關系 -->
             <key column="fk_role_id"/>
             <!-- 讓Role認識User --><!-- 中間表,通過什么字段,跟User表產生關系 -->
             <many-to-many class="User" column="fk_user_id"/>
            </set>
           </class>
          </hibernate-mapping>



          <hibernate-mapping package="com.wepull.hibernate.pojo">
           <class name="User" table="tbl_user">
            <id name="userId" column="pk_user_id">
             <generator class="native"/>
            </id>
            
            <property name="userName" column="uesr_name"/>
            
            <set name="roles" table="tbl_user_role">
             <key column="fk_user_id"/>
             <many-to-many class="Role" column="fk_role_id"/>
            </set>
           </class>
          </hibernate-mapping>

          posted @ 2012-06-27 15:53 千面獨行客 閱讀(127) | 評論 (0)編輯 收藏

          SSH項目 利用項目中的pojo類和配置文件反轉生成數據庫

          public class Export{
           
           private void mian(String[] args) {

            Configuration cfg = new Configuration().configure();
            
            SchemaExport export = new SchemaExport(cfg);
            
            export.create(true, true);
            
           }

          }

          posted @ 2012-06-27 15:49 千面獨行客 閱讀(327) | 評論 (0)編輯 收藏

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          搜索

          最新評論

          • 1.?re: 我多想告訴你
          • 煽情……
          • -- _小丸子
          • 2.?re: 我多想告訴你
          • 面對愛情的男人都是情圣,文筆自然也有所提高。小樣,煽情了吧 /偷笑……
          • -- _小丸子
          • 3.?re: 我多想告訴你
          • 到底是什么事兒觸發了你如此之深的感受啊?前提是這是你寫的,嘿嘿~
          • --巧克力
          • 4.?re: 走過自己
          • 剛開始看,呵呵幾個錯別字,看了之后有點兒小沉重,才發現大姐原是個心思很細膩的男生,文筆還可以喲,嘿嘿~
          • --巧克力
          • 5.?re: 無題
          • 我覺得自恃清高沒啥不好的,呵呵~
          • --巧克力

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 晋中市| 濮阳市| 哈密市| 进贤县| 靖江市| 祥云县| 平遥县| 镇赉县| 桐柏县| 三门峡市| 尼勒克县| 太原市| 静海县| 扎赉特旗| 呼玛县| 青阳县| 杭锦旗| 石楼县| 牟定县| 溆浦县| 寿阳县| 布尔津县| 罗江县| 无为县| 温泉县| 民权县| 汉中市| 五大连池市| 开化县| 砚山县| 崇文区| 宜春市| 浦县| 峨边| 元氏县| 浦东新区| 安仁县| 连州市| 兴和县| 垣曲县| 内丘县|