Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate映射引用了错误的外键_Hibernate_Spring Data Jpa_Foreign Keys - Fatal编程技术网

Hibernate映射引用了错误的外键

Hibernate映射引用了错误的外键,hibernate,spring-data-jpa,foreign-keys,Hibernate,Spring Data Jpa,Foreign Keys,我有以下表格: 候选人/职位 | id | candidate_id | role_id | |----|--------------|---------| PK: id Index, unique: (candidate_id, role_id) // Composite key 兴趣标签 | id | name | |----|------| PK: id | id | candidates_roles_id | interest_tags_id | |----|------------

我有以下表格:

候选人/职位

| id | candidate_id | role_id |
|----|--------------|---------|
PK: id
Index, unique: (candidate_id, role_id) // Composite key
兴趣标签

| id | name |
|----|------|
PK: id
| id | candidates_roles_id | interest_tags_id |
|----|---------------------|------------------|
PK: id
Index: candidates_roles_id, interest_tags_id 
候选人\角色\兴趣\标签

| id | name |
|----|------|
PK: id
| id | candidates_roles_id | interest_tags_id |
|----|---------------------|------------------|
PK: id
Index: candidates_roles_id, interest_tags_id 
我想使用
候选角色.id
键作为
候选角色兴趣标签
中的外键,但出于某种原因,Hibernate/JPA在
候选角色
表中使用复合键:

Foreign key (...:candidates_roles_interest_tags [candidates_roles_id])) must have same number of columns as the referenced primary key (candidates_roles [role_id,candidate_id])
在我的代码中,我定义了以下实体:

@Entity(name = "CandidateRoleInterestTags")
@Table(name = "candidates_roles_interest_tags")
@Audited
public class CandidatesRolesInterestTags {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(unique = true, nullable = false, precision = 10)
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY, targetEntity = CandidateRole.class)
    @JoinColumn(name = "candidates_roles_id", referencedColumnName = "id")
    @MapsId
    private CandidateRole candidateRole;

    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("interest_tag_id")
    private InterestTag interestTag;
    ...
}

@实体
@表(name=“候选人\角色”,
索引={
@索引(name=“PRIMARY”,columnList=“id”,unique=true),
@索引(name=“idx\u candidate\u role”,columnList=“candidate\u id,role\u id”,unique=true),
}
)
@审计
公共类CandidateRole实现了可序列化{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
@列(唯一=真,可空=假,精度=10)
私有int-id;
@许多酮
@JoinColumn(name=“候选者_id”)
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class,property=“id”)
@JsonIdentityReference(alwaysAsId=true)
@NotFound(action=NotFoundAction.IGNORE)
私人候选人;
@许多酮
@JoinColumn(name=“role\u id”)
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class,property=“id”)
@JsonIdentityReference(alwaysAsId=true)
@NotFound(action=NotFoundAction.IGNORE)
私人角色;
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
@连接柱({
@JoinColumn(name=“候选者\角色\ id”,referencedColumnName=“id”),
})
私人设定的利息;
...
}

我错过了什么?我做错了什么?

你的意图不清楚。我从您的映射中看到,您尝试使用
候选人\角色\兴趣\标记。候选人\角色\ id
作为
候选人\角色.id
的外键。同时,您想使用
候选角色.id
作为
候选角色\u兴趣标签.id
的外键?