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.

Environment

Windows 64, Java 7 update 40

Status

Assignee

Vlad Mihalcea

Reporter

Nayden Gochev

Fix versions

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure