您的位置:首页 > 数据库

dynamic-insert dynamic-update mutable="false" (让hibernate生成的sql不包括所有字段、指定不可变的实体)

2011-10-17 16:15 507 查看
Hibernate生成update语句,会更新所有的列。

在有些情况下,例如包含几百列的一个遗留表,在该表中,即使最简单的操作的sql语句也很大,必须关闭这个启动时

的sql生成,并切换到运行时生成的动态语句。当大量实体时,也会影响启动时间,因为hibernate必须为CURD提前生

成所有SQL语句:

区别就是:

Hibernate: insert into USER (user_Name) values (?)

Hibernate: insert into USER (user_Name, password) values (?, ?)

配置:

view
plaincopy
to clipboardprint?

<class name="User" table="USER" dynamic-insert="true" dynamic-update="true">

view
plaincopy
to clipboardprint?

@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)

使实体不可变:

一个特定类的实例可以是不可变的。

效果:

没有sql打印,也没有报错,也就是忽略了更新操作

配置:

view
plaincopy
to clipboardprint?

<class name="User" table="USER" dynamic-insert="true" dynamic-update="true"

mutable="false">

view
plaincopy
to clipboardprint?

@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true,mutable=false)

view
plaincopy
to clipboardprint?

@org.hibernate.annotations.AccessType

The
annotation @org.hibernate.annotations.AccessType
should be considered deprecated for FIELD
and PROPERTY access. It is still useful however if you
need to use a custom access type.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐