从 MainTableEntity 引用 MasterDataEntity 的外键有错误的列数

A Foreign key refering MasterDataEntity from MainTableEntity has the wrong number of column

我有一个主数据table。这个 table 的用途只是保存数据(因此它与其他 table 没有关系)。

这是 MasterDataEntity

@Id
@Column(name = "TYPE_ID")
private Integer id;

@Id
@Column(name = "DESCRIPTION")
private String description;

在另一个table(功能table)中,我想加入这个table。喜欢:

这是 MainTableEntity:

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "TYPE_ID")
private MasterDataEntity masterDataEntity;

这里的逻辑意图是 Maintable 应该包含 MasterTable 的 Type_Id 之一(甚至不是强制所有行)。

我不想在 MasterTable 中存储有关 MainTable 的任何信息。我想要的只是可以将 master table 中的现有值添加到 main table.

除上述之外,我还做了以下查询来标记 FK 关系:

ALTER TABLE MAIN_TABLE ADD TYPE_ID NUMBER;

ALTER TABLE MAIN_TABLE ADD FOREIGN KEY (TYPE_ID ) REFERENCES MASTER_TABLE(TYPE_ID );

使用上面的代码我得到了错误: 从 MainTableEntity 引用 MasterDataEntity 的外键具有错误的列数。应该是 2.

我尝试查看根本原因,但无法获得任何有用的信息。我是 Hibernate 的新手,根据我的要求,我可能会做错事。

谁能告诉我这里出了什么问题,我应该怎么做才能实现我的意图?

谢谢

P.S: 我只提到了相关信息。 MainEntity 中显然还有许多其他列,而 MasterEntity 只有 2 列。如果需要任何信息,请告诉我。

可能是因为MasterDataEntity有多个主键,因为iddescription字段有@Id注解,
它应该只有一个用于 TYPE_ID :

@Id
@Column(name = "TYPE_ID")
private Integer id;

@Column(name = "DESCRIPTION")
private String description;