Hibernate hbm2ddl.auto=update 不更新 MySQL 中的列定义 [英] Hibernate hbm2ddl.auto=update doesn't update column definitions in MySQL
问题描述
我正在尝试使用 hbm2ddl.auto = 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;
和
'mycolumn' bigint(20) not null default 0
'mycolumn' bigint(20) not null default 0
在 MySQL 中.
为什么 hbm2ddl 不更新这些东西?是否可以强制进行此类更新?我想说 hbm2ddl 删除列的默认值并更改类型的长度.
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
不会修改现有的表列定义.做一些测试我发现:
hibernate.hbm2ddl.auto" value="update
won't modify existing table column definitions. Doing some testing I found that:
hibernate.hbm2ddl.auto" value="update
将添加一个尚不存在的 db 列.
hibernate.hbm2ddl.auto" value="update
will add a db column that doesn't already exist.
hibernate.hbm2ddl.auto" value="update
不会删除实体中已删除/不再存在的数据库列.
hibernate.hbm2ddl.auto" value="update
will not delete a db column that is removed/no longer in your entity.
hibernate.hbm2ddl.auto" value="update
不会修改已经创建的数据库列.
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.
见:
需要明确 hibernate.hbm2ddl.auto=update
这篇关于Hibernate hbm2ddl.auto=update 不更新 MySQL 中的列定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!