隨筆 - 6  文章 - 129  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 827222
          • 排名 - 49

          最新評論

          閱讀排行榜

          評論排行榜

          映射文件
          <hibernate-mapping>
              <class name="org.gecs.hibernate.test.AdDepartment" table="AD_DEPARTMENT" schema="BARCODE"
                     dynamic-insert="true" dynamic-update="true">
                  <id name="adDepartmentId" type="long">
                      <column name="AD_DEPARTMENT_ID" precision="22" scale="0" />
                      <generator class="sequence">
                          <param name="sequence">AD_DEPARTMENT_SEQ</param>
                      </generator>
                  </id>
                  <property name="departmentName" type="string">
                      <column name="DEPARTMENT_NAME" length="50" not-null="true" />
                  </property>
                  <property name="active" type="java.lang.Character" insert="false" update="true">
                      <column name="ACTIVE" length="1" />
                  </property>
                  <property name="createdTime" type="date" insert="false" update="false">
                      <column name="CREATED_TIME" length="7" />
                  </property>
                  <property name="createdUser" type="string">
                      <column name="CREATED_USER" length="20" not-null="true" />
                  </property>
                  
                  <many-to-one name="parentDepartment" column="PARENT_DEPARTMENT_ID"/>
                  
                  <set name="childDepartment" cascade="save-update" lazy="true" inverse="true">
                      <key column="PARENT_DEPARTMENT_ID"/>
                      <one-to-many class="org.gecs.hibernate.test.AdDepartment"/>
                  </set>

              </class>
          </hibernate-mapping>

          表結構:
          測試代碼:
          public void testSave() {
                  AdDepartment department = new AdDepartment();
                  department.setDepartmentName("華南資訊處");
                  department.setCreatedUser("bob");
                  
                  AdDepartment child_department = new AdDepartment();
                  child_department.setDepartmentName("PCBA應用系統部");
                  child_department.setCreatedUser("bob");
                  child_department.setParentDepartment(department);
                  //
                  department.getChildDepartment().add(child_department);
                  
                  Transaction tran = session.beginTransaction();
                  session.save(department);
                  //session.save(child_department);
                  tran.commit();
              }

          效果:


          posted on 2011-07-07 15:35 Ke 閱讀(1396) 評論(1)  編輯  收藏 所屬分類: hibernate

          FeedBack:
          # re: hibernate 映射自身一對多雙相關聯[未登錄] 2014-06-20 09:03 1
          樓主還在富士康?  回復  更多評論
            
          主站蜘蛛池模板: 偏关县| 唐海县| 九台市| 武陟县| 长岛县| 郧西县| 乐亭县| 海伦市| 得荣县| 伊吾县| 岑巩县| 读书| 阿拉善右旗| 泰州市| 阿拉善盟| 驻马店市| 南丹县| 南昌县| 三河市| 永登县| 越西县| 台州市| 铜陵市| 民勤县| 香格里拉县| 晴隆县| 夏津县| 彰化市| 茂名市| 娄烦县| 江达县| 石楼县| 陇南市| 连云港市| 玉门市| 马边| 苗栗市| 凤阳县| 天台县| 安达市| 安吉县|