JPQl在查询中有错误

时间:2015-06-04 07:21:52

标签: java java-ee jpa jpql

Query query=entityManager.createQuery("Select e from StudentQualification e where e.student=:id");
@Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id")
    private Integer id;
    @ManyToOne
    @JoinColumn(name="student_id")
    private Student student;
    @ManyToOne
    @JoinColumn(name="qualification_type")
    private QualificationType qualificationType;
    @Column(name="obtain_marks")
    private Integer obtainMarks;
    @Column(name="total_marks")
    private Integer totalMarks;
    @Column(name="institute")
    private String institute;
    @Column(name="year_of_completion")

查询执行出错:参数值[1]与预期类型不匹配[com.autosoft.fortune.model.Student(n / a)]     我的查询在上面,然后我的类属性应该做什么

1 个答案:

答案 0 :(得分:1)

  
    

我也在做这个" query.setParameter(" id",studentId);"在我的下一行代码中

  

看看你的SQL是什么:

 Select e from StudentQualification e where e.student=:id"
                                            ^^^^^^^^^

e.student的类型为Student private Student student;,而不是简单的整数。

因此,请填充id填充的学生对象,而不是id。