JPA (Hibernate) forign key definition on @JoinTable does not work

Description

I am developing an application using JPA 2.1 with Hibernate 4.3 as the persistance provider.

For the sacke of readability and better maintainance, I want to explicitly name every possible think and not to rely on the hibernate naming strategy.

I am using the newly introduced @ForignKey annotation to customize the forign key constraint name, and it works fine for @JoinColumn associated with @ManyToOne relationships.

The problem comes when trying to customise the forign key constraints generated for @ManyToMany relationship using a @JoinTable, the provider do not use my provided name, and revert back to its randomly generated name.

for example:
Assuming we have an entity called collection:

correctly generate the following ddl

but when i try to use it with @ManyToMany association, it does not work as expected:

the generated ddl doesnot honor my provided names, and revert to the auto generated random names:

So, what is wrong here?

by the way, I tried to use foregnKey attribute on the @JoinColumn itself (it seems wrong, but i tried it anyway) and it does not help either:

it does not work either:

what is the correct way to make this work?

Thanks

Environment

None

Assignee

Gail Badner

Reporter

joef

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