开发者

JPA/Hibernate - updating database schema after changing PK of an entity

I need to change the primary key (@Id) of an entity from natural key to a new field that represents a surrogate key (it will use @GeneratedValue(strategy=GenerationType.AUTO)).

What is the easiest way to update the database schema other than droppi开发者_如何学Pythonng the table and letting Hibernate to create it again?

I was trying to let Hibernate update the schema automagically with hibernate.hbm2ddl.auto set to update, but it didn't work out. I suppose that Hibernate autoupdate doesn't support such drastic changes of database schemas.


If it were only one entity, I'd

  • make the changes in the database manually (SQL)
  • and update the Hibernate mapping accordingly
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜