ManyToMany table 与 3 个相关的 table

ManyToMany table with 3 related tables

我有这个 UML 图:

我做这样的实体(和其他能正常工作的实体一样)

Entity.java

@Entity
@Table(name = "entity")
public class Entidad extends BaseEntity {

    protected String name;

    protected String image;

    protected String foundationNotes;

    protected String alias;

    protected Boolean excludeNotifications;

    protected String notes;

    //[...]

    @OrderBy("id")
    @ManyToMany
    protected Set<EntityHeader> headersType = new HashSet<EntityHeader>();

    //[...]

    @OrderBy("id")
    @ManyToMany
    protected Set<Member> candidatures = new HashSet<Member>();

    @OrderBy("id")
    @ManyToMany
    protected Set<Proposal> proposals = new HashSet<Proposal>();

    //[Getters and Setters]

Proposal.java

 @Entity
    @Table(name = "proposal")
    public class Proposal implements Serializable {


    @Id
    @ManyToOne
    private Entidad entity;

    @Id
    @ManyToOne
    private Candidature candidature;

    @ManyToOne
    private SendMethod sendMethod;

    //[Getters and Setters]

Candidature.java

@Entity
@Table(name = "candidature")
public class Candidature extends BaseEntity {

    private String reference;

    private Integer year;

    private Date date;

    private Boolean accepted;

    private Boolean supports;

    private String notes;

    @ManyToOne
    private Category category;

    @ManyToOne
    private ScopeCandidature scope;

    @OrderBy("id")
    @ManyToMany
    private Set<Proposal> proponents = new HashSet<Proposal>();

    @OrderBy("id")
    @ManyToMany
    private Set<Member> members = new HashSet<Member>();

    //[Getters and setters]

但是当我尝试编译它时抛出

Foreign key (FK_ffsm4eg8pctsa9yuvqm4kq1my:send_method [])) must have same number of columns as the referenced primary key (proposal [entity_id,candidature_id])

我认为问题出在 SendMethod 列中,因为我有更多的中间 tables(即 Entity.java[= 中调用的 headersType 38=]) 并且工作正常,所以我不知道如何使用 3 table 关系来做到这一点。

我解决了问题,在实体 SendMethod 我有:

@ManyToOne
private Proposal proposal;

当我删除它工作正常。