Hibernate hbm2ddl.auto = update不会更新MySQL中的列定义 [英] Hibernate hbm2ddl.auto=update doesn't update column definitions in MySQL
问题描述
我试图用hbm2ddl.auto = update更新现有的表。
几个表中有几列,其中数据库列定义从实体中的声明更改。像
@Column(name =mycolumn,nullable = false,length = 10)
private mycolumn;
和
<在MySQL中,'mycolumn'bigint(20)not null default 0
。
为什么hbm2ddl不更新这些东西?是否有可能强制这种更新?
我想说hbm2ddl去除列的默认值并改变类型的长度。
hibernate.hbm2ddl.autovalue =update
不会修改现有的表列定义。做一些测试我发现:
$ b
hibernate.hbm2ddl.autovalue =update
会添加一个db列那还不存在。
hibernate.hbm2ddl.autovalue =update
不会删除已删除/不再删除的数据库列在你的实体中。
hibernate.hbm2ddl.autovalue =update
不会修改具有已经创建完成。
您需要备份表格数据,将其删除并重新启动应用程序以使表格模式重新与您的实体同步。然后重新载入您的数据。
和
I'm trying to update existing table with hbm2ddl.auto = update.
There is several columns in several tables where database column definitions changes from declaration in entities. Like
@Column(name="mycolumn", nullable=false, length=10)
private Long mycolumn;
and
'mycolumn' bigint(20) not null default 0
in MySQL.
Why hbm2ddl doesn't update such things? And is it possible to force such update? I want to say hbm2ddl to remove default value of column and change length of type.
hibernate.hbm2ddl.auto" value="update
won't modify existing table column definitions. Doing some testing I found that:
hibernate.hbm2ddl.auto" value="update
will add a db column that doesn't already exist.
hibernate.hbm2ddl.auto" value="update
will not delete a db column that is removed/no longer in your entity.
hibernate.hbm2ddl.auto" value="update
will not modify a db column that has already been created.
You'll need to backup the table data, drop it and restart your application to get that table's schema back in sync with your entity. Then reload your data.
See:
Need clarity on hibernate.hbm2ddl.auto=update
and
Hibernate hbm2ddl.auto possible values and what they do?
这篇关于Hibernate hbm2ddl.auto = update不会更新MySQL中的列定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!