Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
When declaring a mapping as follows:
@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 tocreate-drop
, the following schema is being generated: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.