We're updating the issue view to help you get more done. 

In a @ManyToMany assoctiation the @JoinColumn foreignKey is not taken into considertion when generating the association database schema

Description

When declaring a mapping as follows:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 @Entity @Table(name = "EMPLOYEE") public class Employee { @Id @GeneratedValue private Long id; @ManyToMany @JoinTable(name = "EMPLOYEE_PROJECT", joinColumns = @JoinColumn(name = "EMPLOYEE_ID", foreignKey = @ForeignKey(name = "FK_EMPLOYEE")), inverseJoinColumns = @JoinColumn(name = "PROJECT_ID", foreignKey = @ForeignKey(name = "FK_PROJECT"))) private Set<Project> projects; }
1 2 3 4 5 6 7 8 9 10 11 @Entity @Table(name = "PROJECT") public class Project { @Id @GeneratedValue private Long id; @ManyToMany(mappedBy="projects") private Set<Employee> employees; }

the generated schema is

1 2 3 4 5 6 7 8 9 create table EMPLOYEE (id bigint not null, primary key (id)) create table EMPLOYEE_PROJECT (EMPLOYEE_ID bigint not null, PROJECT_ID bigint not null, primary key (EMPLOYEE_ID, PROJECT_ID)) create table PROJECT (id bigint not null, primary key (id)) alter table EMPLOYEE_PROJECT add constraint FKc9v0x49gwfm2m9wal4r6fujq6 foreign key (PROJECT_ID) references PROJECT alter table EMPLOYEE_PROJECT add constraint FKa9av8l4b215ry58ocy8h646ge foreign key (EMPLOYEE_ID) references EMPLOYEE

Environment

None

Status

Assignee

Andrea Boriero

Reporter

Andrea Boriero

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.0.6

Priority

Major