When migrating from hibernate 4 to 5 and having
hibernate.hbm2ddl.auto to update
hibernate.implicit_naming_strategy to legacy-jpa
in the persistence.xml.
During the SchemaUpdate hibernate 5 recreate the databases foreign keys and unique keys when running against an existing database (hibernate 4 generated database).
Also the foreign key/unique key prefix are difference. Hibernate 4 uses UK_ or FK_ where as hibernate use UK or FK. Also the foreign key hash key has changed too.
see https://forums.hibernate.org/viewtopic.php?f=1&t=1042969 for more information.
The attachment foreignkeybefore.sql shows the schema after running against hibernate 4 and foreignkeyafter.sql show the same schema after upgrading to hibernate 5.
foreighkeyentities.zip contains the entities i used to generate the database
Wildfly 10 Final, Hibernate 5.0.7, Mysql 5.5
@John Burgess totally agree! In our case, we simply can't afford to drop all existing FKs and re-create via Hibernate 5 without incurring extended downtime.
As long as this remains unfixed, the following custom naming strategy is used successfully by us in order to replicate the naming EJB3NamingStrategy that we had used before.
This is not necessarily an exact replication, but proved enough for our purposes.
See inline comments for details.
I have the same problem, and the custom renaming strategy didn't help. I need to set hbm2ddl to update because I'm using envers, but hibernate tries to recreated all the FK even if they already exist. I also tried to drop them all, but it also tries to recreate the REVINFO table.
Any suggestion? Is this a bug or am I missing something? I've already restored dbs with hibernate 4 and envers, this is only happening with hibernate 5.
This issue is hitting us as well, and our use case (admittedly reasonably unusual) is a local HSQLDB database used by a desktop application, so seamless backwards compatibility with existing databases is a must.
We've just had to drop back to Hibernate 4 for now, but it'd be great if we were able to upgrade.