spring 数据创建了不必要的唯一约束

spring data creates unnecessary unique constraints

我有一个 spring 引导应用程序并使用以下用户模型 class。

 @Entity
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String name;
    private String emailAddress;
    private Boolean active;
    private String password;
    private boolean techLead;
    private boolean sdm;
    private boolean admin;

    @OneToMany(fetch = FetchType.EAGER)
    private Set<Circle> sdmForCircle;

    @OneToMany(fetch = FetchType.EAGER)
    private Set<Node> techLeadForNode;

    @OneToMany(fetch = FetchType.EAGER)
    private Set<Operator> userWorkingForOperator;

..................

一旦我加载 Spring 引导应用程序,它就会自动为 sdmForCircle、userWorkingForOperator 和 techLeadForNode 创建表,但这些表是在创建时带有不必要的唯一约束的。我想停止自动添加唯一约束。

请推荐。

如果您不想要唯一性,请改用 ManyToMany。

另一种方法可能是关闭自动 ddl 生成。 您可以通过添加 Spring 启动属性来实现:

spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=none