In hibernate 5 Schema update re create foreign keys and unique keys against hibernate 4 DB

Description

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

Environment

Wildfly 10 Final, Hibernate 5.0.7, Mysql 5.5

Activity

Show:
Shrisha Radhakrishna
April 5, 2017, 2:03 PM

@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.

Andreas Vallen
May 26, 2017, 10:26 AM
Edited

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.

Saul Giordani
July 10, 2017, 11:36 AM

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.

Michael Berry
June 25, 2018, 6:46 AM

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.

Olaf Ziems
December 12, 2019, 3:45 PM

@Saul Giordani: Your description sounds more like HHH-13779

Assignee

Unassigned

Reporter

Darrell Wu

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure