【发布时间】:2020-07-28 23:18:22
【问题描述】:
我看过一些关于它的帖子,但没有一个对我有帮助。
为什么@JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT)) 不起作用?
public class ClassA {
@Id
private String id;
@NotNull
private String someProperty;
@OneToMany(mappedBy = "classA")
private Set<ClassB> bs;
}
public class ClassB {
@Id
private String id;
@NotNull
private String someProperty;
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
private ClassA classA;
}
当应用程序启动时,它仍然会创建 fks,尽管我有明确的配置。
create table class_a (id varchar(255) not null, some_property varchar(255), primary key (id));
create table class_b (id varchar(255) not null, some_property varchar(255), class_a_id varchar(255), primary key (id));
alter table if exists class_b add constraint FKjpk05raxduof60eee8p6khbch foreign key (class_a_id) references class_a
application.properties
spring.datasource.url=jdbc:postgresql://localhost:5432/my-spring-data-sample
spring.datasource.username=postgres
spring.datasource.password=***
spring.jpa.hibernate.ddl-auto=create
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL95Dialect
谢谢!
【问题讨论】:
-
显示你得到的错误。
-
没有错误。问题是,当应用程序启动时,它仍然会创建 fks,尽管我有明确的配置。
标签: hibernate jpa spring-data-jpa