Hibernate 不带外键的Spring数据JPA@JoinColumn

Hibernate 不带外键的Spring数据JPA@JoinColumn,hibernate,jpa,spring-data-jpa,Hibernate,Jpa,Spring Data Jpa,我看过一些关于它的帖子,但没有一篇对我有帮助 为什么@JoinColumn(foreignKey=@foreignKey(value=ConstraintMode.NO_CONSTRAINT))不起作用 public class ClassA { @Id private String id; @NotNull private String someProperty; @OneToMany(mappedBy = "classA

我看过一些关于它的帖子,但没有一篇对我有帮助

为什么@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;
}
应用程序属性

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
谢谢

  • 我可以看到在hibernate中出现的一个bug,它已经在hibernate版本5.3.3中修复

  • 我可以看到在旧版本中直接使用hibernate扩展的选项

@org.hibernate.annotations.ForeignKey(name=“none”)
@许多酮
私人甲级;
@OneToMany(mappedBy=“classA”)
@org.hibernate.annotations.ForeignKey(name=“无”)
私有集bs;

显示您收到的错误。没有错误。问题是,当应用程序启动时,它仍然会创建fks,尽管我已明确将其配置为不创建。关于旧版本:我已经阅读了此选项,但我没有在关系的两个方面都尝试过!现在它工作了!谢谢我使用的是hibernate版本5.4.18.Final。不应该以我在问题中提到的方式工作?再次感谢!我打开了一个问题。
    @org.hibernate.annotations.ForeignKey(name = "none")
    @ManyToOne
    private ClassA classA;

    
    @OneToMany(mappedBy = "classA")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private Set<ClassB> bs;