I currently have the following objects persisting successfully:
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?
You can't have multiple @Id
annotations in the same entity. Use a composite ID instead.
Example.