Wrong DDL generated by hibernate when using MappedSuperclass containing ManyToMany relation

Description

Hibernate DDL is generating wrong FK constraints when we have MappedSupperclass containing ManyToMany relation and if we have more then 2 classes extending it.(doesn't work for 2,3,4 .. works for 1 or the first extending entity only )

I have a MappedSupperclass


And I have several classes that extend this class which are Entities ( more then 1 )

All of them look like (you must have more then 1 ! ) :

The problem is the SQL DDL script that is generated by org.hibernate.cfg.Configuration#generateSchemaCreationScript is using the same FK name for each entity after the second one.
So the generated SQL script looks like this :

As you can notice.. the first one (the abstract one is ok).. the second one is also ok.. but each other entity that extends the mapped super class have the same constraint name which is invalid.

I've tried to debug the problem and saw that it in generateSchemaCreationScript method in org.hibernate.Configuation class contains the following snippet :

org.hibernate.Configuration.java

And here this "fk" ... fk.getName() is the same for each FK... while it should be different because fk.getName() is used inside sqlCreateString method to generate the actual SQL. I believe something is wrong when TableMappings are created.

Attachments

1

Activity

Vlad MihalceaMarch 14, 2016 at 2:48 PM
Edited

This does not replicate with 5.0.0-Final. For the 4.x branches, there is also a PR.

Vlad MihalceaMarch 14, 2016 at 2:28 PM

This does not replicate on 5.0 anymore. I'll add a test case to prove it.

Steve EbersoleOctober 28, 2015 at 3:25 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Steve EbersoleOctober 27, 2015 at 7:15 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Steve EbersoleApril 2, 2015 at 10:32 PM

Can you try this with 5.0? It should be fixed there.

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Created July 30, 2014 at 12:44 PM
Updated May 5, 2022 at 11:09 AM
Resolved March 14, 2016 at 2:48 PM