JPA: @JoinTable - Both columns are Primary Keys.. How do I stop that?

前端 未结 2 762
粉色の甜心
粉色の甜心 2021-01-16 18:14

This is my annotation I use to generate my Join Table.

@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = \"service_operations\", 
        joinColumns         


        
2条回答
  •  攒了一身酷
    2021-01-16 18:19

    I fixed my problem by adding the following changes:

    I changed my @OneToMany to a @ManyToMany annotation

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "workflow_services", 
            joinColumns = @JoinColumn(name = "workflow_id"), 
            inverseJoinColumns = @JoinColumn(name = "service_id"))
    public Set getServices() {
        return services;
    }
    

    I added a Set workflows; association in my Service object

    @ManyToMany(mappedBy="services")  // map info is in person class
    public Set getWorkflows() {
        return workflows;
    }
    

提交回复
热议问题