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)
).
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
精彩评论