Hibernate 映射 - “无法确定类型”
我目前成功保留了以下对象:
- 人名字等。
- 考试标题、日期等。
我现在想创建第三个表考试结果。对于这个表,我认为它应该是人员 ID、考试 ID 和结果,这是一个多对多的关系。
@Entity
public class ExamResult {
private Exam exam;
private Person person;
private double value;
@Id
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name="EXAM_ID")
public Exam getExam() {
return exam;
}
public void setExam(Exam exam) {
this.exam = exam;
}
@Id
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name="PERSON_ID")
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
}
错误:
<块引用>org.hibernate.MappingException:无法确定类型:Person,表:ExamResult,列:[org.hibernate.mapping.Column(person)]
我想我可能会以错误的方式处理这个问题,但我可以'不知道如何继续处理这种关系 教程。
有什么想法吗?
I currently have the following objects persisting successfully:
- Person first name, etc.
- Exams title, date, etc.
I'd like to now create a third table Exam results. For this table I believe it should be person ID, exam ID and result, and this is a many to many relationship.
@Entity
public class ExamResult {
private Exam exam;
private Person person;
private double value;
@Id
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name="EXAM_ID")
public Exam getExam() {
return exam;
}
public void setExam(Exam exam) {
this.exam = exam;
}
@Id
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name="PERSON_ID")
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
}
The error:
org.hibernate.MappingException: Could not determine type for: Person, at table: ExamResult, for columns: [org.hibernate.mapping.Column(person)]
I think I may be going about this the wrong way, but I can't work out how to proceed with this relationship from the
tutorial.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同一实体中不能有多个
@Id
注释。请改用复合 ID。示例。
You can't have multiple
@Id
annotations in the same entity. Use a composite ID instead.Example.