views:

377

answers:

1

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?

+4  A: 

You can't have multiple @id anotations in the same entity, use a composite id instead. Example

Wiliam Witter
Thanks, that example does look like what I'm trying to achieve. I am going through it.
Pool