3
我正在使用spring-boot-1.5.4和spring-data-jpa,我试图在spring.jpa.hibernate.ddl-auto=create
期间覆盖自动生成的外键名称。覆盖指向复合键的外键名称JPA/Hibernate
对于简单的ID,我能够覆盖它:simple_fk
Hibernate: alter table my_entity add constraint simple_fk foreign key (simple_id) references simple
但不适合外键与复合ID:FKms12cl9ma3dk8egqok1dasnfq
Hibernate: alter table my_entity add constraint FKms12cl9ma3dk8egqok1dasnfq foreign key (composite_id1, composite_id2) references composite
什么是错我的代码?我也试过@PrimaryKeyJoinColumn
。
请参阅下面的类定义。
@Entity
public class Simple {
@Id
private long id;
}
@Entity
public class Composite {
@Id
private CompositeId id;
}
@Embeddable
public class CompositeId {
@Column
private long id1;
@Column
private long id2;
}
@Entity
public class MyEntity {
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(name = "simple_fk"),
name = "simple_id", referencedColumnName = "id")
private Simple simple;
@ManyToOne
@JoinColumns(foreignKey = @ForeignKey(name = "composite_fk"), value = {
@JoinColumn(name = "composite_id1", referencedColumnName = "id1"),
@JoinColumn(name = "composite_id2", referencedColumnName = "id2")
})
private Composite composite;
}