Hibernate不同意这种结构。我错过了什么吗?它引发的错误:
org.hibernate.MappingException:无法找到具有逻辑名称的列:进程中的version_id
有关如何在保持复合键结构的同时进行修复的任何建议?
的DataModel
版本有很多动作
版本有很多流程;
public class Version {
@Id
@Column(name = "id")
public int Id;
}
行动有一个过程
行动有一个版本
public class Action {
// Action has a composite key (ID and Version ID)
@Id
@Column(name = "id")
public int id;
@Id
@ManyToOne
@JoinColumn(name = "version_id")
public Version version;
@ManyToOne
@JoinColumns({
@JoinColumn(name = "process_id", referencedColumnName = "id"),
@JoinColumn(name = "version_id", referencedColumnName = "version_id")
})
public Process process;
}
流程有很多动作
流程有一个版本
public class Process {
// Process has a composite key (ID and Version ID)
@Id
@Column(name = "id")
public int id;
@Id
@ManyToOne
@JoinColumn(name = "version_id")
public Version version;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "process", targetEntity = Action.class)
public List<Action> actions= new ArrayList<Action>();
}
答案 0 :(得分:0)
在Action类中有两列名为version_id的列。尝试将第二个version_id重命名为process_version_id:
public class Action {
// Action has a composite key (ID and Version ID)
@Id
@Column(name = "id")
public int id;
@Id
@ManyToOne
@JoinColumn(name = "version_id")
public Version version;
@ManyToOne
@JoinColumns({
@JoinColumn(name = "process_id", referencedColumnName = "id"),
@JoinColumn(name = "process_version_id", referencedColumnName = "version_id")
})
public Process process;
}