property mapping has wrong number of columns exception - Play-framework

12,670

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?

Share:
12,670
Abhishek
Author by

Abhishek

Updated on July 02, 2022

Comments

  • Abhishek
    Abhishek almost 2 years

    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,

    Student.java

    @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