In a @OneToMany association the @JoinColumn foreignKey is not taken into consideration 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 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 @Entity(name = "Person") public class Person { @Id @GeneratedValue private Long id; public Person() {} @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinTable(name = "person_phone", joinColumns = @JoinColumn(name = "person_id", foreignKey = @ForeignKey(name = "PERSON_ID_FK")), inverseJoinColumns = @JoinColumn(name = "phone_id", foreignKey = @ForeignKey(name = "PHONE_ID_FK")) ) private List<Phone> phones = new ArrayList<>(); public List<Phone> getPhones() { return phones; } } @Entity(name = "Phone") public class Phone { @Id @GeneratedValue private Long id; private String number; public Phone() {} public Phone(String number) { this.number = number; } public Long getId() { return id; } public String getNumber() { return number; } }

and generating the schema using hibernate.hbm2ddl.auto set to create-drop, the following schema is being generated:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 CREATE TABLE Person ( id BIGINT NOT NULL , PRIMARY KEY ( id ) ) CREATE TABLE person_phone ( person_id BIGINT NOT NULL , phone_id BIGINT NOT NULL ) CREATE TABLE Phone ( id BIGINT NOT NULL , number VARCHAR(255) , PRIMARY KEY ( id ) ) ALTER TABLE person_phone ADD CONSTRAINT UK_m5nffi7o8ge7rr71ah3yhur8t UNIQUE (phone_id) ALTER TABLE person_phone ADD CONSTRAINT FK81wfdg8mla92eu8uuhphw551t FOREIGN KEY (phone_id) REFERENCES Phone ALTER TABLE person_phone ADD CONSTRAINT FK4t02ig57t70dqj9gr23ov6uwf FOREIGN KEY (person_id) REFERENCES Person

The @ForeignKey name doesn't propagate to the underlying database schema, which still uses a randomly assigned FK name.

Test will be attached after knowing the issue id.

Environment

None

Status

Assignee

Andrea Boriero

Reporter

Vlad Mihalcea

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

5.0.5

Priority

Major