I am getting the exception org.hibernate.AnnotationException: A Foreign key refering Teacher from Student has the wrong number of column. should be 2
The code is as follows. Can some one please help me with this code , what am I doing wrong ? :-( I have eliminated get/set from all classes
DB Schema:
Teacher(id,name)
Student(id , teacher_id, teacher_name)
Code:
@Entity
@Table(name="Teacher")
public class Teacher implements Serializable {
@EmbeddedId
private PK pk = new PK();
@OneToMany(cascade = {CascadeType.ALL})
@JoinColumn(name="teacher_id")
private List<Student> student;
public List<Student> getStudent() {
return student;
}
public void setStudent(List<Student> student) {
this.student = student;
}
}
/////////////////////
@Entity
@Table(name="Student")
public class Student implements Serializable {
@Id
@Column(name="id")
private int id;
@ManyToOne
@JoinColumns ( {@JoinColumn(nullable=false, name="id"),
@JoinColumn(nullable=false, name="name")})
private Teacher teacher;
}
///////////////////////////
@Embeddable
public class PK implements Serializable
{
private int id;
private String name;
}