开发者

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

开发者 https://www.devze.com 2023-04-01 11:05 出处:网络
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)).

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

精彩评论

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

关注公众号