随笔 - 6  文章 - 129  trackbacks - 0
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(14)

随笔档案(6)

文章分类(467)

文章档案(423)

相册

收藏夹(18)

JAVA

搜索

  •  

积分与排名

  • 积分 - 815441
  • 排名 - 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 阅读(4867) 评论(0)  编辑  收藏 所属分类: hibernate

只有注册用户登录后才能发表评论。


网站导航: