I am a beginner with play framework.Again a question on JPA and mappings in play framework,
I have a student table and a mentor table bound by a one to one relationship.
Student table :
id, name, class, grade
Mentor table:
id, name, department, student_id
In the above, a mentor may or may not have a student bound to him/her. I am making the mentor Model with a one to one mapping,
@OneToOne
@JoinColumn(name="fk_student_id", referencedColumnName="id")
private student Student;
When I try to run this, I get an
A JPA error occurred (Unable to build EntityManagerFactory): property mapping has wrong number of columns: models.Mentor.student type: models.Student.
I am sure I have mapped all the Student fields as below,
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@Column(name="name")
private String name;
@Column(name="class")
private String cls;
@Column(name="grade")
private String grade;
What am I missing here?
Thanks for your time.
Regards, Abi
Are you sure this is working code for Play Framework? There are some differences between Play and standard JPA when creating your model. This fragment:
@OneToOne
@JoinColumn(name="fk_student_id", referencedColumnName="id")
private student Student;
is wrong. Should be something like
@OneToOne
@JoinColumn(name="fk_student_id") //removed the id reference, let JPA manage it
public Student student; //note order of class and var name
Also, you are defining an 'id' field, which is not needed when you extend from Model. Are you extending from Model?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With