Hibernate hbm2ddl.auto=update doesn't update column definitions in MySQL

梦想与她 提交于 2019-11-26 11:12:38

问题


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.


回答1:


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?



来源:https://stackoverflow.com/questions/15978368/hibernate-hbm2ddl-auto-update-doesnt-update-column-definitions-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!