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