Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate mapping - "Could not determine type"

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?

like image 592
Pool Avatar asked Mar 16 '10 20:03

Pool


1 Answers

You can't have multiple @Id annotations in the same entity. Use a composite ID instead. Example.

like image 191
William Witter da Silva Avatar answered Oct 26 '22 02:10

William Witter da Silva