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

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 827342
          • 排名 - 49

          最新評論

          閱讀排行榜

          評論排行榜

          通過設置hibernate映射文件的class處 dynamic-insert="true" dynamic-update="true" 和property 里面的insert="false" update="false" 實現 .

          兩處都要配置!

          <property></property>標簽屬性:update=”true|false”

          如果設置為false,則在hibernate的update語句里面沒有<property>標簽所指明的屬性所對應的字段。

          同理,insert=”true|false”

          如果設置為false,則在hibernate的insert語句里面沒有<property>標簽所指明的屬性所對應的字段。

          這樣的弊端是無法從表單上填寫信息了。

          <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>

              </class>
          </hibernate-mapping>
          注:insert="false" update="false" 的作用是不對當前字段進行insert和update操作,這樣hibernate就不會在未指明默認列的情況下將數據庫表中默認值字段清空,但同時也會造成無法對此字段插入或更新非默認值。


          posted on 2011-07-07 14:55 Ke 閱讀(4906) 評論(0)  編輯  收藏 所屬分類: hibernate
          主站蜘蛛池模板: 成武县| 平定县| 茶陵县| 唐河县| 那坡县| 同仁县| 丰台区| 沂源县| 柳州市| 舞阳县| 离岛区| 垣曲县| 通化县| 鲜城| 莱州市| 海伦市| 河曲县| 阿合奇县| 古浪县| 工布江达县| 大埔区| 称多县| 枣阳市| 凉山| 开封县| 兰坪| 无为县| 昭觉县| 绩溪县| 汶川县| 微博| 扶余县| 剑阁县| 霸州市| 南汇区| 浦江县| 安溪县| 潮州市| 当阳市| 昌宁县| 昭平县|