通過(guò)設(shè)置hibernate映射文件的class處 dynamic-insert="true" dynamic-update="true" 和property 里面的insert="false" update="false" 實(shí)現(xiàn) .
兩處都要配置!
<property></property>標(biāo)簽屬性:update=”true|false”
如果設(shè)置為false,則在hibernate的update語(yǔ)句里面沒有<property>標(biāo)簽所指明的屬性所對(duì)應(yīng)的字段。
同理,insert=”true|false”
如果設(shè)置為false,則在hibernate的insert語(yǔ)句里面沒有<property>標(biāo)簽所指明的屬性所對(duì)應(yīng)的字段。
這樣的弊端是無(wú)法從表單上填寫信息了。
<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" 的作用是不對(duì)當(dāng)前字段進(jìn)行insert和update操作,這樣hibernate就不會(huì)在未指明默認(rèn)列的情況下將數(shù)據(jù)庫(kù)表中默認(rèn)值字段清空,但同時(shí)也會(huì)造成無(wú)法對(duì)此字段插入或更新非默認(rèn)值。
posted on 2011-07-07 14:55
Ke 閱讀(4910)
評(píng)論(0) 編輯 收藏 所屬分類:
hibernate