通過設置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 閱讀(4899)
評論(0) 編輯 收藏 所屬分類:
hibernate